facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.41k stars 1.83k forks source link

relay-compiler does not generate params.text for the extended Query type #4362

Open Mozuha opened 1 year ago

Mozuha commented 1 year ago

Given the query something like:

graphql`
  query emailExistsQuery($email: String!) {
    emailExists(email: $email)
  }
`

with schema:

type Query {
  emailExists(email: String!): Boolean
}

running relay-compiler does not generate params.text but assigns null to it, so in the generated file, the return value of the node will be:

"params": {
    "cacheID": {some id},
    "id": null,
    "metadata": {},
    "name": "emailExistsQuery",
    "operationKind": "query",
    "text": null  // here
  }

The example above is returning Boolean, but changing it to other GraphQL default scalar types (Int, Float, String, ID) resulted in the same behaviour.

Environment:

sibelius commented 1 year ago

Can you try in the last version?

Mozuha commented 1 year ago

@sibelius Do you mean v14.0.0? If so, the result did not change.

Mozuha commented 1 year ago

@sibelius I just noticed that the problem is not returning GraphQL scalar types. The real issue is that the relay compiler in my environment does not generate params.text for Query, although it does for Mutation. I tried with Mutation which returns Boolean and params.text was generated correctly. I have no clue why this happens yet but I wanted to let you know first.

Mozuha commented 1 year ago

@sibelius Okay, I found the reason. In my GraphQL schema, I put emailExists in the extended Query type:

extend type Query {
  emailExists(email: String!): Boolean
}

Once I moved it into the original Query type definition, the relay compiler generated the correct params.text.

By the way, in the file generated with the extended Query type it was importing ClientRequest from relay-runtime and assigned it as a type of node (const node: ClientRequest), while in the file generated with the original Query type it was importing ConcreteRequest and assigned it as a type of node (const node: ConcreteRequest). And I cannot find ClientRequest in the type definition of relay-runtime.

zhangwei712 commented 11 months ago

I have the same problem, is there any way to fix it?