Skip to content

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

@n1ru4l

Description

@n1ru4l

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions