Webpack - Expected [object] to be a GraphQL schema error thrown with apollo-server-lambda app

Viewed 535

When I'm webpacking my apollo lambda app I consistently get the following error displayed at the bottom.

I've found "solutions" to this problem on git issue boards. https://github.com/apollographql/apollo-server/issues/4983

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 case for me:

$ npm ls graphql
server@1.0.0 /Git/myapp
└── graphql@15.5.1 

I've added the following which is purported to be a solution. But still no joy.

graphql$: path.resolve(__dirname, './node_modules/graphql/index.js'),

const path = require("path")
const nodeExternals = require('webpack-node-externals');


const config = {
  mode: 'production',
  entry: {
    ShopApiHandler: "./graphql/shop-api/handler.ts", // produces lambda handler ShopApiHandler/index.handler
  },
  target: 'node',
  module: {
    rules: [
        {
            test: /\.(graphql|gql)$/,
            loader: 'graphql-tag/loader',
            exclude: /node_modules/,
          },
      // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
      {
        test: /\.(tsx?)$/,
        loader: 'ts-loader',
        exclude: [
          [
            path.resolve(__dirname, 'node_modules'),
            path.resolve(__dirname, '.serverless'),
            path.resolve(__dirname, '.webpack'),
          ],
        ],
        options: {
          transpileOnly: true,
          experimentalWatchApi: true,
        },
      },
    ],
  },
  resolve: {
    extensions: ['.ts', '.js'],
    alias: {
      graphql$: path.resolve(__dirname, './node_modules/graphql/index.js'),
  },
  },
  output: {
    filename: "[name]/index.js",
    path: path.resolve(__dirname, ".dist/"),
    libraryTarget: 'commonjs',

  },
  //externals: [nodeExternals()], // in order to ignore all modules in node_modules folder

}

When deploying the application to lambda and running it i get the following Error:

2021-07-04T20:07:52.273+10:00   2021-07-04T10:07:52.272Z    undefined   ERROR   Uncaught Exception  {"errorType":"Error","errorMessage":"Expected { __validationErrors: undefined, description: undefined, extensions: undefined, astNode: undefined, extensionASTNodes: [], _queryType: Query, _mutationType: Mutation, _subscriptionType: undefined, _directives: [@cacheControl, @include, @skip, @deprecated, @specifiedBy], _typeMap: { Query: Query, Mutation: Mutation, Shop: Shop, ID: ID, String: String, ShopInput: ShopInput, 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.","stack":["Error: Expected { __validationErrors: undefined, description: undefined, extensions: undefined, astNode: undefined, extensionASTNodes: [], _queryType: Query, _mutationType: Mutation, _subscriptionType: undefined, _directives: [@cacheControl, @include, @skip, @deprecated, @specifiedBy], _typeMap: { Query: Query, Mutation: Mutation, Shop: Shop, ID: ID, String: String, ShopInput: ShopInput, 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 t.assertSchema (/var/task/ShopApiHandler/index.js:28:7335251)","    at b (/var/task/ShopApiHandler/index.js:28:7340500)","    at t.assertValidSchema (/var/task/ShopApiHandler/index.js:28:7340190)","    at C (/var/task/ShopApiHandler/index.js:28:7038732)","    at k (/var/task/ShopApiHandler/index.js:28:7037831)","    at Object.t.execute (/var/task/ShopApiHandler/index.js:28:7036943)","    at Object.t.generateSchemaHash (/var/task/ShopApiHandler/index.js:28:42878)","    at c.generateSchemaDerivedData (/var/task/ShopApiHandler/index.js:14:141)","    at new t.ApolloServerBase (/var/task/ShopApiHandler/index.js:2:171971)","    at new c (/var/task/ShopApiHandler/index.js:28:51635)"]}

0 Answers
Related