I'm using extend type Query to put my queries into separate files and it works great with the following code:
const schema = `
scalar GraphQLDate
# Queries that the schema supports
type Query {
dummy: [String]
}
`;
export default makeExecutableSchema({
typeDefs: [
schema,
donations.schema,
projects.schema,
partners.schema,
donors.schema
],
resolvers
})
An example of how I'm extending the Query type is from my donors.js file here:
export const schema = `
# A person who has donated money to one or more projects
type Donor {
id: Int!
user_id: Int
name: String!
slug: String!
donated_sum: Float
image: String
donations: [Donation]
}
extend type Query {
# Donors who have given money to projects
donors: [Donor]
}
`
It works great but requires the dummy query.
if I remove the type Query in the variable schema I get the error 'Must provide schema definition with query type or a type named Query.'.
If I change the schema variable to have an empty type Query {} I get the error Error: Query fields must be an object with field names as keys or a function which returns such an object.
So I'm left with having to provide a dummy query that serves no purpose, shows up in GraphiQL and doesn't work if it is called.
@proehlen yes, this is a limitation that @tmeasday has also run into. It's imposed by graphql-js, so there's not much we can do about it.
@helfer OK, thanks for the feedback.
I'm having the same issue. I want to extend the Query (Or rootQuery) type.
How do you resolve that issue?
Oh...
Most helpful comment
I'm having the same issue. I want to extend the Query (Or rootQuery) type.
How do you resolve that issue?