2
votes

I am trying to do schema stitching with apollo but I am getting an error every time I use makeExecutableSchema. The error is the following:

../node_modules/graphql-tools/dist/generate/concatenateTypeDefs.js:9:

-> if (typeDef.kind !== undefined)

TypeError: Cannot read property 'kind' of undefined

I have reproduced the problem even when just copying the basic example on Apollo's website

const { ApolloServer, gql, makeExecutableSchema } = require("apollo-server");
const { addMockFunctionsToSchema, mergeSchemas } = require("graphql-tools");

const chirpSchema = makeExecutableSchema({
  typeDefs: `
      type Chirp {
        id: ID!
        text: String
        authorId: ID!
      }

      type Query {
        chirpById(id: ID!): Chirp
        chirpsByAuthorId(authorId: ID!): [Chirp]
      }
    `
});

addMockFunctionsToSchema({ schema: chirpSchema });

const authorSchema = makeExecutableSchema({
  typeDefs: `
      type User {
        id: ID!
        email: String
      }

      type Query {
        userById(id: ID!): User
      }
    `
});

addMockFunctionsToSchema({ schema: authorSchema });

const schema = mergeSchemas({
  schemas: [chirpSchema, authorSchema]
});

const server = new ApolloServer(schema);

server.listen().then(({ url }) => {
  console.log(`???? Server ready at ${url}`);
});

What am I doing wrong? However I try I always get the same error when using makeExecutableSchema.

1

1 Answers

2
votes

From what i see you are using [email protected] in this version ApolloServer constructor receives an options parameter

constructor(options)

you should pass new ApolloServer({ schema: schema }) instead of new ApolloServer(schema)

i tried that with the example you gave and it worked :)