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

Change TypedDocumentNode to a specification for embedding Operation/Fragment and Variable types within a TypeScript type #143

Open
n1ru4l opened this issue Aug 19, 2022 · 2 comments
Assignees

Comments

@n1ru4l
Copy link
Collaborator

n1ru4l commented Aug 19, 2022

In terms of typed-document-node I think we should rather make it a specification for baking-in types into a TypeScript type and showing how to extract the type from it:

type OperationString<TVariables, TResult> = string & {
  ["  __graphql_types_v1"]?: (variables: TVariables) => TResult
}

In case we later decide to change the method we could call it __graphql_types_v2 or sth.

What do you think?


Related:

@n1ru4l
Copy link
Collaborator Author

n1ru4l commented Feb 27, 2023

I did a quick test in graphql code generator by replacing TypedDocumentNode<Result, Variables> with as import('graphql').DocumentNode & { __apiType?: (variables: unknown) => FilmItemFragment };.

It seems to work quite well!

export const FilmItemFragmentDoc = {
  kind: 'Document',
  definitions: [
    {
      kind: 'FragmentDefinition',
      name: { kind: 'Name', value: 'FilmItem' },
      typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Film' } },
      selectionSet: {
        kind: 'SelectionSet',
        selections: [
          { kind: 'Field', name: { kind: 'Name', value: 'id' } },
          { kind: 'Field', name: { kind: 'Name', value: 'title' } },
          { kind: 'Field', name: { kind: 'Name', value: 'releaseDate' } },
          { kind: 'Field', name: { kind: 'Name', value: 'producers' } },
        ],
      },
    },
  ],
} as unknown as import('graphql').DocumentNode & { __apiType?: (variables: unknown) => FilmItemFragment };

@n1ru4l
Copy link
Collaborator Author

n1ru4l commented Feb 27, 2023

Related #148

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

1 participant