graphql-tools
graphql-tools copied to clipboard
[executor-http] Infer whether variables are optional or not
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.