Error: Query root type must be provided #610
Opened this issue ยท 6 comments
I'm receiving the error:
Error: Query root type must be provided
Here is my schema:
schema.graphql
schema {
query: ClientQuery
...
}
type ClientQuery {
...
}
I am importing it with graphql-importer
import { importSchema } from 'graphql-import'
const baseTypeDefs = importSchema('../pg-fresh-client/schema/schema.graphql')
Shouldn't this be valid?
@lpender - did you resolve this issue?
here's the issue โ graphql-import
gathers definition types, but unintentionally skips over some important types like the SchemaType, leading to the above issue.
in particular, in https://github.com/graphcool/graphql-import/blob/e5c4b078e4747aa6e3ffec37139451f85011478f/src/index.ts#L263-L271 we should actually be allowing the SchemaTypeDefinition. im not sure what the behavior should be when you find multiple SchemaTypeDefinitions, though, should they be combined? should we throw a warning or just fail if there are collisions, given that we shouldn't expect child documents to re-define the schema
type?
i believe
is where graphql-js
parses out the proper types, and here is where it defaults back to Query
if this SchemaTypeDefinition isn't set:
Any fix for this?
Remember typedefs its just a template string, so.
import path from 'path';
import { importSchema } from 'graphql-import';
import { makeExecutableSchema } from 'graphql-tools';
import resolvers from './resolvers';
const typeDefs = importSchema(path.join(__dirname, './root/Query.graphql'));
export default makeExecutableSchema({
typeDefs: `
${typeDefs}
schema {
query: Query,
}
`,
resolvers,
});
Works
Just provide type Query
with any method.
const { ApolloServer, gql } = require("apollo-server");
const todos = [
{ task: "work for today", completed: true },
{ task: "finish home work", completed: false }
];
const typeDefs = gql`
type Todo {
task: String
completed: Boolean
}
type Query {
getTodos: Todo
}
`;
const server = new ApolloServer({
typeDefs: typeDefs
});
server.listen().then(({ url }) => {
console.log(`server listening on ${url}`);
});