apollographql / apollographql/apollo-tooling
Schema created by apollo client:download-schema is not type-compatible with buildClientSchema()
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 460
- PR merge metrics
- No merged PRs in 30d
Description
**Intended outcome:**
I'm following the example on [how to create a mock server](https://www.apollographql.com/docs/apollo-server/features/mocking/). The basic gist is that after obtaining a schema via introspection (for which I used `apollo client:download-schema`), you can feed it into `buildClientSchema()` as use it to create a mock server.
**Actual outcome:**
Passing the imported JSON schema generates a type (TypeScript) error:
```
Argument of type '{ "__schema": { "queryType": { "name": string; }; "mutationType": { "name": string; }; "subscriptionType": null; "types": ({ "kind": string; "name": string; "description": null; "fields": ({ "name": string; "description": null; "args": never[]; "type": { ...; }; "isDeprecated": boolean; "deprecationReason": null; } ...' is not assignable to parameter of type 'IntrospectionQuery'.
Types of property '__schema' are incompatible.
Type '{ "queryType": { "name": string; }; "mutationType": { "name": string; }; "subscriptionType": null; "types": ({ "kind": string; "name": string; "description": null; "fields": ({ "name": string; "description": null; "args": never[]; "type": { ...; }; "isDeprecated": boolean; "deprecationReason": null; } | { ...; })[];...' is not assignable to type 'IntrospectionSchema'.
Types of property 'queryType' are incompatible.
Property 'kind' is missing in type '{ "name": string; }' but required in type 'IntrospectionNamedTypeRef'.
```
**How to reproduce the issue:**
Pass a schema obtained from an introspection query (`apollo client:download-schema`) in JSON fromat to the `buildClientSchema()` function.
The introspection query was done against Apollo Engine.
Taking a closer look at the types are, and specifically following the path down to the Query object specifically, we find
```ts
export interface IntrospectionQuery {
readonly __schema: IntrospectionSchema;
}
export interface IntrospectionSchema {
readonly queryType: IntrospectionNamedTypeRef;
// ...
}
export interface IntrospectionNamedTypeRef<
T extends IntrospectionType = IntrospectionType
> {
readonly kind: T['kind'];
readonly name: string;
}
```
**Versions**
```
"apollo": "^2.18.0",
"apollo-server": "^2.9.0",
```
Contributor guide
Research direction
Reproduce the issue by running apollo client:download-schema against Apollo Engine, then pass the JSON output to buildClientSchema(). Compare the generated schema shape with the IntrospectionQuery types shown in the report; done means the downloaded schema is accepted as an IntrospectionQuery without the reported TypeScript incompatibility.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100