I’m getting troubles getting started with the Apol...
# guide
t
I’m getting troubles getting started with the Apollo guide, https://serverless-stack.com/examples/how-to-create-an-apollo-graphql-api-with-serverless.html Looks like the config changed recently and playground is not longer supported.
There’s a bug in this guide/setup but I’m not able to find what the problem is, so far in the logs it complains about a different graphql versions:
Copy code
Error: Cannot use GraphQLSchema "{ __validationErrors: undefined, description: undefined, extensions: {}, astNode: { kind: "SchemaDefinition", operationTypes: [Array] }, extensionASTNodes: [], _queryType: Query, _mutationType: undefined, _subscriptionType: undefined, _directives: [@include, @skip, @deprecated, @specifiedBy], _typeMap: { Query: Query, String: String, Boolean: Boolean, __Schema: __Schema, __Type: __Type, __TypeKind: __TypeKind, __Field: __Field, __InputValue: __InputValue, __EnumValue: __EnumValue, __Directive: __Directive, __DirectiveLocation: __DirectiveLocation }, _subTypeMap: {}, _implementationsMap: {} }" from another module or realm. Ensure that there is only one instance of "graphql" in the node_modules directory. If different versions of "graphql" are the dependencies of other relied on modules, use "resolutions" to ensure only one version is installed. <https://yarnpkg.com/en/docs/selective-version-resolutions> Duplicate "graphql" modules cannot be used at the same time since different versions may have different capabilities and behavior. The data from one version used in the function from another could produce confusing and spurious results.
Anyone faced this before?
f
Hey @Tonny (sstNerd), I managed to reproduce this on my end. looking into it w/ @thdxr. Will keep you posted.
s
This is the same issue I had here: https://serverless-stack.slack.com/archives/C01JG3B20RY/p1653316132844659 I believe the deduped invalid bit was resolved, but the graphqlschema having several instances is the same
f
@Tonny (sstNerd) finally tracked down the issue,
graphql
doesn’t play well with
esm
, so you need to make 2 changes: 1. In ur
stacks/MyStack.ts
, change this
Copy code
const api = new GraphQLApi(stack, "ApolloApi", {
    server: "functions/lambda.handler",
  });
to
Copy code
const api = new GraphQLApi(stack, "ApolloApi", {
    server: {
      handler: "functions/lambda.handler",
      bundle: {
        format: "cjs",
      },
    },
  });
2. In your
backend/functions/lambda.ts
, remove this line
Copy code
playground: IS_LOCAL,
t
ahhh got it, awesome ty @Frank and @thdxr! I’ll try it on my end
f
@sforman yeah the different graphql versions part was really misleading in this case. There was just 1 instance of `graphql`… checked node_modules, checked the lock file, checked npm ls, checked esbuild analysis even lol
Turned out to be graphql not compatible with
esm
.
s
All good, I had no idea 😅