Webpack puts multiple copies of `graphql` in the bundle, leading to "Expected {...} to be a GraphQL schema" errors from graphql-js
See original GitHub issueHello π
Iβm attempting to set up a project using apollo-server-lambda
, but Iβm encountering the following issue when initializing the ApolloServer
:
Error: Expected { __validationErrors: undefined, description: undefined, extensions: undefined, astNode: undefined, extensionASTNodes: [], _queryType: Query, _mutationType: undefined, _subscriptionType: undefined, _directives: [@cacheControl, @include, @skip, @deprecated, @specifiedBy], _typeMap: { Query: Query, String: String, CacheControlScope: CacheControlScope, Upload: Upload, Int: Int, Boolean: Boolean, __Schema: __Schema, __Type: __Type, __TypeKind: __TypeKind, __Field: __Field, __InputValue: __InputValue, __EnumValue: __EnumValue, __Directive: __Directive, __DirectiveLocation: __DirectiveLocation }, _subTypeMap: {}, _implementationsMap: {} } to be a GraphQL schema.
at (webpack://apollo-server-lambda-example/node_modules/graphql/type/schema.js:47:10)
at schema (webpack://apollo-server-lambda-example/node_modules/graphql/type/validate.js:42:28)
at validateSchema (webpack://apollo-server-lambda-example/node_modules/graphql/type/validate.js:66:15)
at schema (webpack://apollo-server-lambda-example/node_modules/graphql/execution/execute.js:150:35)
at assertValidExecutionArguments (webpack://apollo-server-lambda-example/node_modules/graphql/execution/execute.js:98:2)
at executeImpl (webpack://apollo-server-lambda-example/node_modules/graphql/execution/execute.js:60:34)
at execute (webpack://apollo-server-lambda-example/node_modules/apollo-server-core/dist/utils/schemaHash.js:15:31)
at generateSchemaHash (webpack://apollo-server-lambda-example/node_modules/apollo-server-core/dist/ApolloServer.js:274:40)
at generateSchemaDerivedData (webpack://apollo-server-lambda-example/node_modules/apollo-server-core/dist/ApolloServer.js:161:37)
at (webpack://apollo-server-lambda-example/node_modules/apollo-server-lambda/dist/ApolloServer.js:21:0)
I am using the exact same code as the getting started example, so I donβt think the code is the issue here. The error Iβm seeing is nearly identical to apollographql/apollo-client#6621, so Iβm wondering if that issue may be related.
Iβve created a simple example project that you can use to reproduce this issue. You can run the example and reproduce the issue with the commands below:
# Run the lambda container image:
docker run -p 9000:8080 ghcr.io/rmsy/apollo-server-lambda-example
# In a different terminal, invoke the lambda:
curl -X POST -H 'Content-Type: application/json' -d '{"query":"query Query {\n hello\n}\n"}' "http://localhost:9000/2015-03-31/functions/function/invocations"
Below are the package versions used in my example project. (Iβve never used Apollo before, so I donβt know whether or not this issue is new to this version).
βΆ yarn list --pattern "graph|apollo"
yarn list v1.22.5
ββ @apollo/protobufjs@1.0.5
ββ @apollographql/apollo-tools@0.4.9
ββ @apollographql/graphql-playground-html@1.6.26
ββ @apollographql/graphql-upload-8-fork@8.1.3
ββ apollo-cache-control@0.11.6
ββ apollo-datasource@0.7.3
ββ apollo-env@0.6.6
ββ apollo-graphql@0.6.1
ββ apollo-link@1.2.14
ββ apollo-reporting-protobuf@0.6.2
ββ apollo-server-caching@0.5.3
ββ apollo-server-core@2.21.0
ββ apollo-server-env@3.0.0
ββ apollo-server-errors@2.4.2
ββ apollo-server-lambda@2.21.0
ββ apollo-server-plugin-base@0.10.4
ββ apollo-server-types@0.6.3
ββ apollo-tracing@0.12.2
ββ apollo-utilities@1.3.4
ββ graphql-extensions@0.12.8
ββ graphql-tag@2.11.0
ββ graphql-tools@4.0.8
ββ graphql@15.5.0
β¨ Done in 0.26s.
Any help would be appreciated; thank you for your time! π
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (4 by maintainers)
I have also encountered this issue in my Apollo Webpack Typescript project, I have discovered the following:
The extensions order inside the Webpack configuration seems to have a major influence.
This will produce the error:
extensions: [".js", ".mjs", ".ts"],
This will not produce the error:
extensions: [".ts", ".mjs", ".js"]
My experience here is that by adding
".mjs"
to my list of extensions, this issue magically disappeared. For me, it was only happening once my server-side ts node app was being bundled.