Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makeConnectionId doesn't works incorrectly with multiple @connection on a fragment #437

Closed
DZakh opened this issue Mar 21, 2023 · 7 comments

Comments

@DZakh
Copy link
Contributor

DZakh commented Mar 21, 2023

The makeConnectionId works with only one connection and ignores the other ones.

Here's the fragment example:

module Fragment = %relay(`
    fragment ProspectDetailsPartnerOffers_prospect on Prospect {
      id
      partnerOffersStatus
      wholesaleBids(first: 100)
        @connection(key: "ProspectDetailsPartnerOffers_wholesaleBids") {
        edges {
          node {
            ...ProspectDetailsPartnerOffers_wholesaleBid
          }
        }
      }
      prospectBids(first: 100)
        @connection(key: "ProspectDetailsPartnerOffers_prospectBids") {
        edges {
          node {
            id
            wholesaleBid {
              id
            }
          }
        }
      }
    }
  `)

The generated code looks like this:

// ProspectDetailsPartnerOffers_prospect_graphql.res

@live
@inline
let connectionKey = "ProspectDetailsPartnerOffers_prospectBids"

%%private(
  @live @module("relay-runtime") @scope("ConnectionHandler")
  external internal_makeConnectionId: (RescriptRelay.dataId, @as("ProspectDetailsPartnerOffers_prospectBids") _, 'arguments) => RescriptRelay.dataId = "getConnectionID"
)

@live
let makeConnectionId = (connectionParentDataId: RescriptRelay.dataId, ) => {
  let args = ()
  internal_makeConnectionId(connectionParentDataId, args)
}
@zth
Copy link
Owner

zth commented Mar 21, 2023

I'm surprised the compiler allows multiple connections in one fragment. It's not something that'll be supported - move those out to separate fragments if you want the helpers to work (getConnectionNodes and makeConnectionId).

What's the point of having the connection directives both but no arguments for refetching? Or is this just a condensed example?

@zth zth closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2023
@DZakh
Copy link
Contributor Author

DZakh commented Mar 22, 2023

I've created a separate fragment, but the first connection name got prefixed with two underscores in the generated code inside of the makeNode function

image

@zth
Copy link
Owner

zth commented Mar 22, 2023

I've created a separate fragment, but the first connection name got prefixed with two underscores in the generated code inside of the makeNode function

image

Interesting! Could you paste all relevant code?

@DZakh
Copy link
Contributor Author

DZakh commented Mar 22, 2023

My bad, that's the correct behavior 😅

@DZakh
Copy link
Contributor Author

DZakh commented Mar 22, 2023

What's the point of having the connection directives both but no arguments for refetching? Or is this just a condensed example?

There are multiple mutations with

@appendNode(
    edgeTypeName: "WholesaleValuationRequest"
    connections: $connections
)

that update different connections for different edge types on one fragment.

@DZakh
Copy link
Contributor Author

DZakh commented Mar 22, 2023

eg:

module Fragment = %relay(`
  fragment ProspectDetailsPartnerOffers_prospect on Prospect {
    wholesaleBids(first: 100)
      @connection(key: "ProspectDetailsPartnerOffers_wholesaleBids") {
      edges {
        node {
          ...ProspectDetailsPartnerOffers_wholesaleBid
        }
      }
    }
   wholesaleValuationRequests(first: 100, where: { hasWholesaleBid: false })
        @connection(
          key: "ProspectDetailsPartnerOffers_wholesaleValuationRequests"
        ) {
        edges {
          node {
            ...ProspectDetailsPartnerOffers_wholesaleValuationRequest
          }
        }
     }
  }
`)

And

module Mutation = %relay(`
    mutation AcceptValuationRequestMutation(
      $id: ID!
      $amount: Money!
      $expiresAt: Time!
      $connections: [ID!]!
    ) {
      acceptValuationRequest(
        id: $id
        input: { amount: $amount, expiresAt: $expiresAt }
      ) {
        wholesaleBid
          @appendNode(edgeTypeName: "WholesaleBid", connections: $connections) {
          ...ProspectDetailsPartnerOffers_wholesaleBid
          ...ProspectDetailsCreateBidModal_wholesaleBid
        }
        id @deleteRecord
      }
    }
  `)
module Mutation = %relay(`
    mutation SendValuationRequestMutation(
      $prospectID: ID!
      $emailContent: String!
      $wholesalePartnerIDs: [ID!]!
      $connections: [ID!]!
    ) {
      generateValuationRequest(
        input: {
          prospectID: $prospectID
          emailContent: $emailContent
          wholesalePartnerIDs: $wholesalePartnerIDs
        }
      )
        @appendNode(
          edgeTypeName: "WholesaleValuationRequest"
          connections: $connections
        ) {
        ...ProspectDetailsPartnerOffers_wholesaleValuationRequest
      }
    }
  `)

Instead of passing __id I get connections like:

ProspectDetailsPartnerOffers_prospect_graphql.makeConnectionId(
  prospectID->RescriptRelay.makeDataId,
)

@zth
Copy link
Owner

zth commented Mar 23, 2023

Right! That looks good. And it's working as intended now breaking things out to two fragments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants