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

feat(core): Add support for graphql.js’ built-in TypedQueryDocumentNode #3085

Merged
merged 1 commit into from
Mar 20, 2023

Conversation

kitten
Copy link
Member

@kitten kitten commented Mar 19, 2023

Summary

graphql.js now has a built-in type for typed DocumentNodes, which we must adopt to support tools that rely on this type instead of @graphql-typed-document-node/core.

We can maintain our prior approach of having a copied type to maintain backwards- and forwards- compatibility by extending our own type with the type property carrying the types we need. The only difference to the other package is that graphql.js uses a different name for the property: https://github.com/graphql/graphql-js/blob/e171a14/src/utilities/typedQueryDocumentNode.ts#L8-L22

This has been tested with the following ts file:

import { Client, TypedDocumentNode } from '@urql/core';
import type { TypedQueryDocumentNode } from 'graphql';
import type { TypedDocumentNode as LegacyTypedDocumentNode } from '@graphql-typed-document-node/core';

type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
type Variables = Exact<{ [key: string]: never; }>;

const client = new Client({ url: 'test', exchanges: [] });

const x: TypedQueryDocumentNode<{ data: { hello: 'world' } }, Variables> = {} as any;
const y: LegacyTypedDocumentNode<{ data: { hello: 'world' } }, Variables> = {} as any;
const z: TypedDocumentNode<{ data: { hello: 'world' } }, Variables> = {} as any;

const { data: xData } = client.readQuery(x, {})!;
const { data: yData } = client.readQuery(y, {})!;
const { data: zData } = client.readQuery(z, {})!;

let test = xData;
test = yData;
test = zData;

Set of changes

  • Add __ensureTypesOfVariablesAndResultMatching property to TypedDocumentNode

@kitten kitten merged commit 087339b into main Mar 20, 2023
@kitten kitten deleted the feat/graphql-js-typed-documents branch March 20, 2023 07:12
@github-actions github-actions bot mentioned this pull request Mar 20, 2023
@github-actions github-actions bot mentioned this pull request Mar 27, 2023
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

Successfully merging this pull request may close these issues.

2 participants