graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

[executor-http] Infer whether variables are optional or not

Open n1ru4l opened this issue 2 years ago • 0 comments

For the given GraphQL executable document:

const AllFilmsWithVariablesQuery = graphql(/* GraphQL */ `
  query allFilmsWithVariablesQuery($first: Int!) {
    allFilms(first: $first) {
      edges {
        node {
          ...FilmItem
        }
      }
    }
  }
`);

The following does not result in a TypeScript error:

executor({
  document: AllFilmsWithVariablesQuery,
})

As one of the variables is declared as non-nullable the value must be provided. This can be implemented like the following: https://github.com/dotansimha/graphql-code-generator/blob/676063c1e62017398deeb580278448935a0da3df/examples/typescript-esm/src/executeOperation.ts#L8-L9

graphql-request in comparison handles this case and behaves as expected, yielding a better DX.

n1ru4l avatar Feb 13 '23 13:02 n1ru4l