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

Support for imports #80

Closed
patrick91 opened this issue Jan 3, 2018 · 3 comments
Closed

Support for imports #80

patrick91 opened this issue Jan 3, 2018 · 3 comments

Comments

@patrick91
Copy link

Hi, I've tried running graphql-schema-linter on multiple files with the latest version of graphql but the linting breaks with this error:

It looks like you may have hit a bug in graphql-schema-linter.

It would be super helpful if you could report this here: https://github.com/cjoudrey/graphql-schema-linter/issues/new

Error: Query root type must be provided.
    at assertValidSchema (/Users/patrick/Documents/Github/graphql-mock/node_modules/graphql/type/validate.js:78:11)
    at validate (/Users/patrick/Documents/Github/graphql-mock/node_modules/graphql/validation/validate.js:61:35)
    at validateSchemaDefinition (/Users/patrick/Documents/Github/graphql-mock/node_modules/graphql-schema-linter/lib/validator.js:30:41)
    at run (/Users/patrick/Documents/Github/graphql-mock/node_modules/graphql-schema-linter/lib/runner.js:64:56)
    at Object.<anonymous> (/Users/patrick/Documents/Github/graphql-mock/node_modules/graphql-schema-linter/lib/cli.js:15:32)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)

Which seems to be caused by this: graphql/graphql-js#1124

My workaround was to merge all the files with AWK and lint the merged schema,
awk 'FNR==1{print ""}1' ../api/**/*.graphql | graphql-schema-linter .graphql -s

I'm not sure what the best solution to fix this will be, I know there is no official syntax for imports, but there are two "proposal":

I think add some kind of imports support would be great, the only issue is that we still have the error from above, since now the GraphQL library needs a root type. Another solution would be do merge (like I did with the awk) all the files and run the validation on it. Then we need to a mapping between the merged file and the original ones, but shouldn't be difficult :)

What do you think? I might have some time to help this or the next week

@patrick91
Copy link
Author

I just found out that this is already working, if you pass a glob the library will concatenate all the files :)

getSchema() {
if (this.schema) {
return this.schema;
}
var schema;
if (this.options.stdin) {
this.schema = getSchemaFromFileDescriptor(this.stdinFd);
this.sourceMap = new SourceMap({ stdin: this.schema });
} else if (this.options.schemaPaths) {
var paths = this.options.schemaPaths
.map(path => {
if (globHasMagic(path)) {
return globSync(path);
} else {
return path;
}
})
.reduce((a, b) => {
return a.concat(b);
}, []);
var segments = getSchemaSegmentsFromFiles(paths);
this.sourceMap = new SourceMap(segments);
this.schema = this.sourceMap.getCombinedSource();
}
return this.schema;
}

@chapati23
Copy link

@patrick91 how exactly did you get it working?

i'm trying graphql-schema-linter src/**/*.graphql and always get:

Error: Type "Query" was defined more than once.

However, adding extends to all my modularly defined Querys then breaks graphql-import.

Seems there's no way to make both tools happy at the moment :-/

@patrick91
Copy link
Author

I can't find that codebase anymore, but I'm quite sure I didn't define multiple root queries :)

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

No branches or pull requests

2 participants