Skip to content

The result of getIntrospectionQuery does not match IntrospectionQuery type #3409

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

Closed
Woodz opened this issue Dec 6, 2021 · 5 comments · Fixed by #4226
Closed

The result of getIntrospectionQuery does not match IntrospectionQuery type #3409

Woodz opened this issue Dec 6, 2021 · 5 comments · Fixed by #4226

Comments

@Woodz
Copy link

Woodz commented Dec 6, 2021

getIntrospectionQuery only requests the name field from the root queryType object
(https://github.com/graphql/graphql-js/blob/6e48d16f92b9a6df8638b1486354c6be2537033b/src/utilities/getIntrospectionQuery.ts)

queryType { name }

yet the IntrospectionQuery datatype defines queryType as IntrospectionNamedTypeRef (https://github.com/graphql/graphql-js/blob/main/src/utilities/getIntrospectionQuery.ts#L167) which requires kind as well

export interface IntrospectionNamedTypeRef<
  T extends IntrospectionType = IntrospectionType,
> {
  readonly kind: T['kind'];
  readonly name: string;
}

This means that copying the result of the querying a GQL API with the introspection query as JSON and trying to assign to IntrospectionQuery will fail with:

The types of '__schema.queryType' are incompatible between these types.
Property 'kind' is missing in type '{ name: string; }' but required in type 'IntrospectionNamedTypeRef'.

@sibo2000
Copy link

Bumping this.

@conatus
Copy link

conatus commented Apr 26, 2022

Still seeing this issue. At the moment, chucking in a @ts-ignore but would be nice to have a firmer fix.

Exact same situation, passing an introspection in JSON into buildClientSchema. Using the very latest graphql at 16.4.0.

import * as introspectionResult from "../../../graphql.schema.json";

const schema = buildClientSchema(introspectionResult);

Produces the following error:

Argument of type '{ __schema: { queryType: { name: string; }; mutationType: { name: string; }; subscriptionType: null; types: ({ kind: string; name: string; description: string; fields: null; inputFields: null; interfaces: null; enumValues: null; possibleTypes: null; } | ... 9 more ... | { ...; })[]; directives: ({ ...; } | { ...; })...' is not assignable to parameter of type 'IntrospectionQuery'.
  The types of '__schema.queryType' are incompatible between these types.
    Property 'kind' is missing in type '{ name: string; }' but required in type 'IntrospectionNamedTypeRef<IntrospectionObjectType>'

Other issues downstream in users of this library:

@conatus
Copy link

conatus commented Apr 26, 2022

Wondered if making kind option would be enough, and it creates further problems upstream.

export interface IntrospectionNamedTypeRef<
  T extends IntrospectionType = IntrospectionType,
> {
  readonly kind?: T['kind'];
  readonly name: string;
}

@yaacovCR
Copy link
Contributor

@IvanGoncharov is it simply a matter of fixing getIntrospectionQuery to include kind as hinted at above?

@yaacovCR
Copy link
Contributor

Or is that silly because the kind is obvious for root types? And we need a new introspection type for root types?

JoviDeCroock added a commit that referenced this issue Oct 11, 2024
Supersedes #3910
Fixes #3909
Fixes #3409

This puts the Selection-set in line with the expected type
erikwrede pushed a commit to erikwrede/graphql-js that referenced this issue Oct 17, 2024
Supersedes graphql/graphql-js#3910
Fixes graphql/graphql-js#3909
Fixes graphql/graphql-js#3409

This puts the Selection-set in line with the expected type
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 a pull request may close this issue.

4 participants