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

fix: TypeError on different "graphql" versions #115

Merged
merged 1 commit into from
Aug 18, 2020

Conversation

dobrinov
Copy link
Contributor

@dobrinov dobrinov commented Jul 24, 2020

If there is a difference in the versions of "graphql" used by "apollo-link-scalars" and the project including it there might be difference in the structure of the schema instance created by makeExecutableSchema. This is the case with "graphql" 14.x and 15.x. and will result in a TypeError - "The types returned by 'getQueryType()' are incompatible between these types.".

To fix this I am exposing makeExecutableSchema through "apollo-link-scalars" to ensure that the types in the generated schema will be compatible by those expected from withScalars.

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Bug fix

  • What is the current behavior? (You can also link to an open issue here)
    My project is using "graphql" version "15.3.0" and the one used by "apollo-link-scalars" is "14.5.8". I am getting the following TypeError:

app/javascript/gamma/utils/apollo.ts:47:29 - error TS2322: Type 'import(".../dev/.../application/node_modules/graphql/type/schema").GraphQLSchema' is not assignable to type 'import(".../dev/apollo-link-scalars/node_modules/graphql/type/schema").GraphQLSchema'.
  The types returned by 'getQueryType()' are incompatible between these types.
    Type 'Maybe<GraphQLObjectType<any, any>>' is not assignable to type 'Maybe<GraphQLObjectType<any, any, { [key: string]: any; }>>'.
      Type 'GraphQLObjectType<any, any>' is not assignable to type 'Maybe<GraphQLObjectType<any, any, { [key: string]: any; }>>'.
        Types of property 'isTypeOf' are incompatible.
          Type 'import("/Users/dobrinov/dev/receipt-bank/application/node_modules/graphql/jsutils/Maybe").Maybe<import(".../dev/receipt-bank/application/node_modules/graphql/type/definition").GraphQLIsTypeOfFn<any, any>>' is not assignable to type 'import("/Users/dobrinov/dev/apollo-link-scalars/node_modules/graphql/tsutils/Maybe").default<import(".../dev/apollo-link-scalars/node_modules/graphql/type/definition").GraphQLIsTypeOfFn<any, any>>'.
            Type 'GraphQLIsTypeOfFn<any, any>' is not assignable to type 'Maybe<GraphQLIsTypeOfFn<any, any>>'.
              Types of parameters 'info' and 'info' are incompatible.
                Type 'import(".../dev/apollo-link-scalars/node_modules/graphql/type/definition").GraphQLResolveInfo' is not assignable to type 'import(".../dev/receipt-bank/application/node_modules/graphql/type/definition").GraphQLResolveInfo'.
                  Types of property 'fieldNodes' are incompatible.
                    Type 'readonly import(".../dev/apollo-link-scalars/node_modules/graphql/language/ast").FieldNode[]' is not assignable to type 'readonly import(".../dev/.../application/node_modules/graphql/language/ast").FieldNode[]'.
                      Type 'import(".../dev/apollo-link-scalars/node_modules/graphql/language/ast").FieldNode' is not assignable to type 'import(".../dev/receipt-bank/.../node_modules/graphql/language/ast").FieldNode'.
                        Types of property 'loc' are incompatible.
                          Type 'import(".../dev/apollo-link-scalars/node_modules/graphql/language/ast").Location | undefined' is not assignable to type 'import(".../dev/.../application/node_modules/graphql/language/ast").Location | undefined'.
                            Property 'toJSON' is missing in type 'import(".../dev/apollo-link-scalars/node_modules/graphql/language/ast").Location' but required in type 'import(".../dev/receipt-bank/application/node_modules/graphql/language/ast").Location'.
  • What is the new behavior (if this is a feature change)?
    n/a

  • Other information:
    n/a

If there is a difference in the versions of "graphql" used in "apollo-link-scalars" and the project
including it there might be difference in the structure of the sch ema instance created by
`makeExecutableSchema`. This is the case with "graphql" 14.x and 15.x. And will result in a
TypeError - "The types returned by 'getQueryType()' are incompatible between these types.". To fix
this I am exposing `makeExecutableSchema` through "apollo-link-scalars" to ensure that the types in
the generated schema will be compatible by those expected from `withScalars`.
@dobrinov
Copy link
Contributor Author

dobrinov commented Jul 25, 2020

Actually after thinking more about this the right way to do this is to define graphql as "peerDependency". The implementation here will also work and will allow different graphql versions but the "peerDependency" solution is probably the more correct one.

Having a peer dependency means that your package needs a dependency that is the same exact dependency as the person installing your package. This is useful for packages like react that need to have a single copy of react-dom that is also used by the person installing it.

https://classic.yarnpkg.com/en/docs/dependency-types

@eturino
Copy link
Owner

eturino commented Aug 18, 2020

I'll merge this PR and then look about moving it to a peer dependency @dobrinov
Thanks!

@eturino
Copy link
Owner

eturino commented Aug 18, 2020

@all-contributors please add @dobrinov for bug and idea

@allcontributors
Copy link
Contributor

@eturino

I've put up a pull request to add @dobrinov! 🎉

@eturino eturino merged commit 4008797 into eturino:master Aug 18, 2020
@dobrinov dobrinov deleted the export-make-executable-schema branch September 14, 2020 05:22
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 this pull request may close these issues.

None yet

2 participants