graphql-tools: Stitching schema without a Query shows "Query root type must be provided."

Discription

I am trying to stitch two schemas that one of them only contains a Mutation type using the latestgraphql-tools v3.0.0. The error will disappear if any Query type contains more than one field is added to the single-mutation schema.

Since the error is not the same as #659 and that issue has been a while before the v3.0.0 was out, I open this issue. Please close this if you think this is duplicate.

Related issue: #659 Related PR: #746

Intended outcome

Querying Mutation test field should return a string result.

Actual outcome

“Query root type must be provided.” error is returned.

How to reproduce the issue

First schema:

type Query {
  hello: String!
}

Second schema:

type Mutation {
  test: String!
}

Query:

mutation {
  test
}

returned data:

{
  "errors": [
    {
      "message": "Query root type must be provided.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "test"
      ]
    }
  ],
  "data": null
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 16
  • Comments: 32 (3 by maintainers)

Most upvoted comments

We solves this by just filling in

type Query {
  dummy: String
}

Yes, I am using graphql-tools v3.0.0.

Here is my reproduction repo: https://github.com/stomvi/graphql-tools-mutation-stitching

Using express along with express-graphql:

git clone git@github.com:stomvi/graphql-tools-mutation-stitching.git
cd graphql-tools-mutation-stitching
yarn install
yarn start

As I described, the schemas to be merged and the merging is located in the file src/graphql/schema.js. The graphiql will be running at locahost on port 8080. And if you execute an mutation query with: http://localhost:8080/graphql?query=mutation%20%7B%0A%20%20test%0A%7D

you’ll get this response:

{
  "errors": [
    {
      "message": "Query root type must be provided.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "test"
      ]
    }
  ],
  "data": null
}

Please kindly take a look. Thanks!!

same issue here.

so… any plans to fix this? 😞

+1

We experience the same problem, we are using remote schema stitching and one of services we merge with doesn’t have a queries, it has only mutations. We are using GraphQL as our contract which we are sharing with 3rd parties and having ‘dummy’ or other temp types defined in it looks really bad. Is there any chance to fix this?

until this is resolved some other way, I added _dummy Query type fields to my mutation only schemas…

then, after stitching:

const schema = transformSchema(mergedSchemas, [
  new TransformRootFields(
    (_, fieldName) => fieldName == "_dummy" ? null : undefined
  ),
]);

and now there is no more exposed _dummy.

There should still be a better way to do this.

Try this one, It might help you out…

const { ApolloServer, gql } = require(“apollo-server”);

const todos = [{ task: “Open the door”, completed: true }];

const typeDefs = gql` type Todo { task: String! completed: Boolean! }

type Query { getTodos: [Todo] } `;

const server = new ApolloServer({ typeDefs }); server.listen().then(({ url }) => { console.log(Server is listening ${url}); });

@Spolja schema stitching uses GraphQLJS and GraphQLjs needs a query root type provided, so I don’t think we can fix that on our side.