question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack puts multiple copies of `graphql` in the bundle, leading to "Expected {...} to be a GraphQL schema" errors from graphql-js

See original GitHub issue

Hello πŸ‘‹

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

17reactions
botrecommented, May 2, 2021

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"]

4reactions
Josh-a-ecommented, Nov 2, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack'ing your GraphQL Documents
When the bundle is created, Webpack will load the .graphql file and use the GraphQL parser in order to set COMMENT_QUERY to a...
Read more >
Webpack - Expected [object] to be a GraphQL schema error ...
Many of which suggest that the problem is multiple copies of graphql being found in node_modules But that doesn't seem to be the...
Read more >
GraphQL Code Libraries, Tools and Services
A GraphQL library for .NET Core. Easily expose you data model as a GraphQL API or bring together multiple data sources into a...
Read more >
GraphQL Code Libraries, Tools and Services
In addition to mapping domain classes to a GraphQL schema, the core library also provides default implementations of "data fetchers" to query, update,...
Read more >
GraphQL | RedwoodJS Docs
In this way, GraphQL makes fetching data descriptive and predictable. Again, unlike a REST API, a GraphQL API is built on a schema...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found