Graphql-code-generator: Query interface is empty when using an instance of GraphQLSchema

Created on 18 Dec 2018  路  8Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug
Using typescript-resolvers plugin, _QueryResolvers.Resolvers_ are empty when using TypeScript export schema config.

To Reproduce
Steps to reproduce the behavior:

  1. Clone repository:
    git clone -b graphql-ts-emptyQueryResolvers https://github.com/swcarlosrj/SpaceX-API.git
  2. Install dependencies:
    yarn
  3. Generate types:
    yarn generate

Expected behavior
Get the auto generated resolver types.

Environment:

  • OS: macOS Mojave 10.14.2 (18C54)
  • Codegen: 0.15.0
  • Node: 10.10.0

Additional context
Using Url(schema: http://localhost:4000/graphql) schema config (it does work):

export namespace QueryResolvers {
  export interface Resolvers<Context = MyContext, TypeParent = {}> {
    _empty?: _EmptyResolver<Maybe<string>, TypeParent, Context>;
    capsules?: CapsulesResolver<Maybe<(Maybe<Capsule>)[]>, TypeParent, Context>;
    capsule?: CapsuleResolver<Maybe<Capsule>, TypeParent, Context>;
    cores?: CoresResolver<Maybe<(Maybe<Core>)[]>, TypeParent, Context>;
    core?: CoreResolver<Maybe<Core>, TypeParent, Context>;
    ...
  }
  ...
}

Using TypeScript export(schema: src/graphql/schema/index.ts) schema config (it does not work!):

export namespace QueryResolvers {
  export interface Resolvers<Context = MyContext, TypeParent = {}> {
    _empty?: _EmptyResolver<Maybe<string>, TypeParent, Context>;
  }
 ...
}

The motivations for using this configuration is having _nodemon_ & _gql-gen_ watching for the schema & resolver files, having Url as schema config on gql-gen, whenever you change a file, both gql-gen & apollo server will restart where gql-gen will usually finish first then the schema: http://localhost:4000/graphql is not available to auto generate the types.

Is there a better way to resolve this problem than the following conf (which I cannot make it work)?

schema: src/graphql/schema/index.ts
documents: src/graphql/schema/**/*.ts
overwrite: true
watch: true
require:
  - ts-node/register
generates:
  ./src/graphql/types/types.d.ts:
    plugins:
      - typescript-common
      - typescript-server
      - typescript-resolvers

P.D.: The typescript-server plugin is working correctly, what I cannot get are the resolvers, probably I'm missing smth out on the config.

bug waiting-for-release

Most helpful comment

All 8 comments

As far as I can tell, it's not related to resolvers, even typescript-server alone has only a _empty field in a Query interface.

@kamilkisiela thanks for the fast reply, as you've just mentioned, that's what I'm getting when using TypeScript export(schema: src/graphql/schema/index.ts) schema config:

export namespace QueryResolvers {
  export interface Resolvers<Context = MyContext, TypeParent = {}> {
    _empty?: _EmptyResolver<Maybe<string>, TypeParent, Context>;
  }
 ...
}

As you say the _empty resolver which appears above it's generated by the typescript-server plugin but I do have in my config file the typescript-resolvers plugin but anything is being generated as it happens using Url(schema: http://localhost:4000/graphql) schema config

Basically, when I'm using the Url as schema config it does work, using TypeScript export file as schema config doesn't work

Reproduction: https://github.com/dotansimha/graphql-code-generator/pull/1072

The issue here is the extend keyword, seems like an exported GraphQLSchema object treats it weirdly.

馃暤锔廔 will try to 馃攳 investigate that case!

It's mergeGraphQLSchemas from @graphql-modules/epoxy that drops all the fields

Awesome @kamilkisiela , thanks for such incredible work 馃槂

Fixed in 0.15.2 :)

Was this page helpful?
0 / 5 - 0 ratings