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 when query type is in a different file location #36

Closed
emmenko opened this issue Aug 18, 2017 · 4 comments
Closed

Error when query type is in a different file location #36

emmenko opened this issue Aug 18, 2017 · 4 comments
Labels

Comments

@emmenko
Copy link

emmenko commented Aug 18, 2017

Hey there,

I've been trying this library for linting a SDL, however I'm getting this error:

Error: Must provide schema definition with query type or a type named Query.
    at buildASTSchema (/Users/emmenko/dev/src/xxx/node_modules/graphql-schema-linter/node_modules/graphql/utilities/buildASTSchema.js:167:11)
    at validateSchemaDefinition (/Users/emmenko/dev/src/xxx/node_modules/graphql-schema-linter/lib/validator.js:18:51)
    at run (/Users/emmenko/dev/src/xxx/node_modules/graphql-schema-linter/lib/runner.js:47:56)
    at Object.<anonymous> (/Users/emmenko/dev/src/xxx/node_modules/graphql-schema-linter/lib/cli.js:15:32)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)

The reason is most likely that I have the schema spread out to different files (see modularizing schema) and I'm using the extend keyword for extending the Query type.

// schema.js
const SchemaDefinition = `
  type Query {
    version: String
    # See each individual schema for specific queries
  }
  schema {
    query: Query
  }
`;
module.exports = makeExecutableSchema({
  typeDefs: [
    SchemaDefinition,
    user.schema,
    // ...
  ],
  resolvers: {...}
});

// user/schema.gql
type User {...}
extend type Query {
  me: User
}

// foo/schema.gql
type Foo {...}
extend type Query {
  foo: Foo
}

Any idea if this might work?

Many thanks!

@cjoudrey
Copy link
Owner

cjoudrey commented Aug 19, 2017

Great question @emmenko.

I can see a few issues at the moment.

graphql-schema-linter only supports a single schema.graphql file as input. The extend type Query use case is a great example of why we might want to support multiple files as input, i.e. schema/**/*.gql. This is something I will fix soon.

That said, this wouldn't entirely solve your issue since your type Query { .. } and schema { .. } are defined in a JS file instead of a .gql file. I'm not sure if we want the graphql-schema-linter to start accepting .js files as input. Out of curiosity, is there a reason why your schema definition isn't in a .gql as well?

In the meantime, one temporary solution could be to use graphql-js' schemaPrinter in order to obtain a SDL which you can then pipe to graphql-schema-linter.

// dump-schema.js
import { printSchema } from 'graphql/utilities';
const schema = require('./schema.js');
console.log(printSchema(schema));

Then you could do this to validate:

$ node dump-schema.js | graphql-schema-linter --stdin

The downside is that you won't get per-file validation, i.e. the line numbers will be incorrect in the report.

@cjoudrey cjoudrey added the bug label Aug 19, 2017
@emmenko
Copy link
Author

emmenko commented Aug 21, 2017

Hey, thanks for the feedback.

This is something I will fix soon.

Great, looking forward for that ;)

Out of curiosity, is there a reason why your schema definition isn't in a .gql as well?

No reason, I actually moved all pieces of the schema in .gql files. Thanks for the hint!

Other than that, I can wait for a proper usage to avoid doing workarounds. It's not a crucial thing after all.

@cjoudrey
Copy link
Owner

@emmenko v0.0.13 now has support for modularized schemas. 😁

Example:

screen shot 2017-08-27 at 10 42 46 pm

@emmenko
Copy link
Author

emmenko commented Aug 28, 2017

Awesome, thanks!!

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

No branches or pull requests

2 participants