Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Query root type must be provided #610 #73

Open
lpender opened this issue Feb 6, 2018 · 6 comments
Open

Error: Query root type must be provided #610 #73

lpender opened this issue Feb 6, 2018 · 6 comments

Comments

@lpender
Copy link

lpender commented Feb 6, 2018

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?

@relaxedtomato
Copy link

@lpender - did you resolve this issue?

@jnwng
Copy link
Contributor

jnwng commented Apr 6, 2018

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?

@jnwng
Copy link
Contributor

jnwng commented Apr 6, 2018

@RyannGalea
Copy link

Any fix for this?

@Katyadelarosa
Copy link

Katyadelarosa commented May 17, 2018

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

@ali-turki
Copy link

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}`);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants