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

Query interface is empty when using an instance of GraphQLSchema #1061

Closed
itscarlosrufo opened this issue Dec 18, 2018 · 8 comments
Closed
Assignees
Labels
waiting-for-release Fixed/resolved, and waiting for the next stable release

Comments

@itscarlosrufo
Copy link
Contributor

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.

@kamilkisiela
Copy link
Collaborator

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 kamilkisiela changed the title typescript-resolvers plugin: QueryResolvers.Resolvers are empty when using TypeScript export schema config Query interface is empty when using an instance of GraphQLSchema Dec 19, 2018
@itscarlosrufo
Copy link
Contributor Author

@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

@kamilkisiela
Copy link
Collaborator

kamilkisiela commented Dec 19, 2018

Reproduction: #1072

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

🕵️I will try to 🔍 investigate that case!

@kamilkisiela
Copy link
Collaborator

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

@kamilkisiela
Copy link
Collaborator

Reproduction: Urigo/graphql-modules#238

@kamilkisiela
Copy link
Collaborator

Urigo/graphql-modules#238 should fix it

@itscarlosrufo
Copy link
Contributor Author

Awesome @kamilkisiela , thanks for such incredible work 😃

@dotansimha dotansimha added bug waiting-for-release Fixed/resolved, and waiting for the next stable release labels Dec 24, 2018
@dotansimha
Copy link
Owner

Fixed in 0.15.2 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-release Fixed/resolved, and waiting for the next stable release
Projects
None yet
Development

No branches or pull requests

3 participants