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)
We solves this by just filling in
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 withexpress-graphql
:As I described, the schemas to be merged and the merging is located in the file
src/graphql/schema.js
. Thegraphiql
will be running atlocahost
on port8080
. And if you execute an mutation query with: http://localhost:8080/graphql?query=mutation%20%7B%0A%20%20test%0A%7Dyou’ll get this response:
Please kindly take a look. Thanks!!
same issue here.
+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:
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.