Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading to graphql-js 15.0.0 breaks working configuration with message: Field "[...]" already exists in the schema

I am working on an app that is operating fine with 14.6.0, but throws an error message when upgrading graphql to 15.0.0. Before getting to the error message, let's walk through the configuration:

Here's how I'm initializing the app:

export default new ApolloServer({
    schema: makeExecutableSchema({
        typeDefs,
        resolvers: merge(...resolverObjects),
    })
});

...where:

  • typeDefs is an array made up of the plaintext content of .graphql files read from the disk (the app is doing different things so I've logically separated the schema into multiple files).
  • merge is the lodash function that does a deep merge on all resolverObjects.

The first schema in typeDefs is a dummy "base" schema:

type Query {
    _dummy: String
}

type Mutation {
    _dummy: String
}

All the subsequent schemas define new object types and extend the Query and/or Mutation schemas:

extend type Query {
    readStuff: String!
}

extend type Mutation {
    saveStuff: Boolean!
}

In 14.6.0, this setup works fine.

Upgrading to 15.0.0 produces the following error, for every new property of the extended Query and Mutation types:

Field "[...]" already exists in the schema. It cannot also be defined in this type extension.

But it does not already exist. It's only defined in type extensions. What's the problem?

like image 622
Andrei Avatar asked Sep 14 '25 11:09

Andrei


1 Answers

Thanks to Daniel Rearden who commented on the original question, I got to the bottom of it. The problem was that I was importing makeExecutableSchema from apollo-server-express, which depends on graphql-tools version 4.

The latest graphql-tools is version 6. Adding an explicit dependency on this latest version and importing makeExecutableSchema from it allowed me to upgrade to the latest graphql version (15.0.0).

like image 132
Andrei Avatar answered Sep 17 '25 20:09

Andrei