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

TypeError in 2.9.5 #3381

Closed
hyochan opened this issue Oct 5, 2019 · 11 comments
Closed

TypeError in 2.9.5 #3381

hyochan opened this issue Oct 5, 2019 · 11 comments
Labels
🥀 needs-reproduction Lacks a runnable reproduction which can be used to quickly demonstrate a bug.

Comments

@hyochan
Copy link

hyochan commented Oct 5, 2019

I am experiencing TypeError in apollo-server-express@2.9.5. I've not had this error in previous version and I can confirm this in PR. Starting to failing the build in circleci when upgrading the apollo packages.

Below is a log.

(node:5777) UnhandledPromiseRejectionWarning: TypeError: _schema.then is not a function
    at new ApolloServerBase (/Users/dooboolab/Github/dooboolab/hackatalk-server/node_modules/apollo-server-express/node_modules/apollo-server-core/src/ApolloServer.ts:365:40)
    at new ApolloServer (/Users/dooboolab/Github/dooboolab/hackatalk-server/node_modules/apollo-server-express/src/ApolloServer.ts:88:5)
    at Object.<anonymous> (/Users/dooboolab/Github/dooboolab/hackatalk-server/src/app.ts:43:18)
    at Generator.next (<anonymous>)
    at /Users/dooboolab/Github/dooboolab/hackatalk-server/node_modules/merge-graphql-schemas/node_modules/apollo-link/node_modules/tslib/tslib.js:107:75
    at new Promise (<anonymous>)
    at __awaiter (/Users/dooboolab/Github/dooboolab/hackatalk-server/node_modules/merge-graphql-schemas/node_modules/apollo-link/node_modules/tslib/tslib.js:103:16)
    at Object.startServer (/Users/dooboolab/Github/dooboolab/hackatalk-server/src/app.ts:27:12)
    at Object.<anonymous> (/Users/dooboolab/Github/dooboolab/hackatalk-server/src/server.ts:3:1)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Module.m._compile (/Users/dooboolab/Github/dooboolab/hackatalk-server/node_modules/ts-node/src/index.ts:493:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/dooboolab/Github/dooboolab/hackatalk-server/node_modules/ts-node/src/index.ts:496:12)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
    at Object.<anonymous> (/Users/dooboolab/Github/dooboolab/hackatalk-server/node_modules/ts-node/src/bin.ts:158:12)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)

-->

@tomm90
Copy link

tomm90 commented Oct 7, 2019

@hyochan Still experiencing this problem? Having the same issue. Found a solution?

@trevor-scheer
Copy link
Member

Thank you, @hyochan. Can either of you please provide a runnable reproduction?

@trevor-scheer trevor-scheer added the 🥀 needs-reproduction Lacks a runnable reproduction which can be used to quickly demonstrate a bug. label Oct 8, 2019
@hyochan
Copy link
Author

hyochan commented Oct 8, 2019

@trevor-scheer Well, last commit in our project is causing the problem which I've done only the package updates. I think you can easily clone that and test it. We've made our toy project in order to share same experience such as bugs like this.

If this isn't enough, please tell me again. Thank you!

@Santinell
Copy link

Santinell commented Oct 11, 2019

I had the same problem and looks like new release 2.9.6 fixed it

@trevor-scheer
Copy link
Member

Thanks for the update @Santinell, can you please try the latest and let me know if it resolves the issue for you @hyochan?

I have yet to determine the cause, or why it would resolve itself after a patch release with presumably no targeted fix.

@hyochan
Copy link
Author

hyochan commented Oct 14, 2019

@trevor-scheer As you can see here same error is occuring in 2.9.6. @Santinell Are you sure 2.9.6 fixed yours?

@trevor-scheer To test this you can easily clone our repo and yarn && yarn start then you will see the below error.
image

@henry-young
Copy link

henry-young commented Oct 18, 2019

@hyochan I was also experiencing this error.
I found that this issue was caused by different npm modules using conflicting versions of graphql.
My fix included using yarn resolutions to set the version of graphql that your modules will use.

Snippet from my package.json

{
  ...
  "dependencies":{
    "graphql": "^14.5.8"
    ...
  },
  "resolutions": {
    "type-graphql/**/graphql": "^14.5.8"
  }
}

hyochan added a commit to hyochan/hackatalk-server that referenced this issue Oct 18, 2019
- Make resolution version match installed graphql version. Related apollographql/apollo-server#3381.
@hyochan
Copy link
Author

hyochan commented Oct 18, 2019

@henry-young Can't believe I've missed this. Thank you!

@hyochan hyochan closed this as completed Oct 18, 2019
@jaschaio
Copy link

jaschaio commented Oct 21, 2019

Getting the same error using apollo-server-express@2.9.6 and graphql@14.5.8.

I added the same resolution as @henry-young suggest to my package.json, removed the node_modules folder and run yarn install once more but the error still persists.

@jaschaio
Copy link

Ok, I found the error. I passed in an object called schema instead of typeDefs. So although the error looked like the same it was actually caused by something else.

Wrong code:

const server = new ApolloServer( {
        schema,
        resolvers,
        context: authenticate,
        playground: ( config.env === 'development' ),
        introspection: ( config.env === 'development' )
    } );

Corrected:

const server = new ApolloServer( {
        typeDefs,
        resolvers,
        context: authenticate,
        playground: ( config.env === 'development' ),
        introspection: ( config.env === 'development' )
    } );

@henry-young
Copy link

Perhaps there could be better type checking and error messaging.
In the offending code, apollo server assumes that if it isn't a GraphQLSchema then it is a promise of GraphQLSchema.

// apollo-core/ApolloServer.ts - Line 365
    if (_schema instanceof GraphQLSchema) {
      const derivedData = this.generateSchemaDerivedData(_schema);
      this.schema = derivedData.schema;
      this.schemaDerivedData = Promise.resolve(derivedData);
    } else {
      this.schemaDerivedData = _schema.then(schema =>
        this.generateSchemaDerivedData(schema),
      );
    }

Potentially a fix could be to convert non-promise schemas to a promise, resolve that schema promise, then type check the schema against GraphQLSchema.

I've also seen other projects (e.g. class-validator) warn of multiple versions of the library in node_modules, although this case would be a concern for the graphql library.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🥀 needs-reproduction Lacks a runnable reproduction which can be used to quickly demonstrate a bug.
Projects
None yet
Development

No branches or pull requests

6 participants