3.1.1 breaks type inference
See original GitHub issueAfter I upgraded from 3.1.0 to 3.1.1 I got a lot of type errors in my project.
My setup:
- graphql-core-generator with @graphql-codegen/typed-document-node 2.2.2
- urql 2.0.6 with @urql/preact 2.0.3
- graphql 16
- typescript 4.5.4
Query:
query ExampleQuery($id: ID!) {
user(id: $id) {
id
}
}
Generated document:
export type ExampleQueryResult = { user?: { __typename: 'User', id: string } | null | undefined };
export type ExampleQueryVariables = Exact<{
id: Scalars['ID'];
}>;
export const ExampleQueryDocument = {
kind: "Document",
definitions: [
{
kind: "OperationDefinition",
operation: "query",
name: { kind: "Name", value: "ExampleQuery" },
variableDefinitions: [
{
kind: "VariableDefinition",
variable: { kind: "Variable", name: { kind: "Name", value: "id" } },
type: {
kind: "NonNullType",
type: { kind: "NamedType", name: { kind: "Name", value: "ID" } },
},
},
],
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "user" },
arguments: [
{
kind: "Argument",
name: { kind: "Name", value: "id" },
value: {
kind: "Variable",
name: { kind: "Name", value: "id" },
},
},
],
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "id" } },
],
},
},
],
},
},
],
} as unknown as TypedDocumentNode<ExampleQueryResult, ExampleQueryVariables>;
Component:
import { ExampleQueryDocument } from '$api';
import { useQuery } from '@urql/preact';
export function ExampleComponent() {
const [{ data }] = useQuery({
query: ExampleQueryDocument,
variables: {
id: '123',
},
});
const t = data?.user?.id;
return <div>{t}</div>;
}
With v3.1.0
After upgrade to v3.1.1
This seems to be caused by the removal of __resultType
and __variablesType
in https://github.com/dotansimha/graphql-typed-document-node/commit/6ee77c273422bea7df58f92607e54fe73eba673a#diff-9a4ceebe7c6f86856371906c3f061d3b56b7457022b05179884a113e7ced67e8
If I add the properties back using interface augmentation, it works again:
import { DocumentNode } from 'graphql';
declare module '@graphql-typed-document-node/core' {
interface TypedDocumentNode<Result = { [key: string]: any }, Variables = { [key: string]: any }>
extends DocumentNode {
__resultType?: Result;
__variablesType?: Variables;
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:11 (3 by maintainers)
Top Results From Across the Web
9.6. Type Inference — OCaml Programming - GitHub Pages
Type Inference #. OCaml and Java are statically typed languages, meaning every binding has a type that is determined at compile time—that is,...
Read more >Java Type Inference Is Broken: Can We Fix It? - RICE CS
compiler includes a pragmatic but flawed type inference al- ... This paper dissects the type inference algorithm of Java ... 3.1.1 Types.
Read more >Type Inference, Type Improvement, and Type Simplification in ...
with a type inference algorithm, based on the theory of qualified types, to correctly capture ... 3.1.1 The Notion of Record and the...
Read more >10.5.3. Finishing Type Inference
Next, we introduced the unification algorithm for solving constraint sets. That algorithm produces as output a sequence S of substitutions, or it fails....
Read more >Why does regular function break type inference?
UPDATE type Constructors = | BooleanConstructor | ObjectConstructor | StringConstructor type DefaultFactory<T> = (props: Data) => T; ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Glad I found this thread, I confirm @graphql-typed-document-node/core: 3.1.1 is breaking the inference, 3.1.0 is good.
Works here, too. 👍