-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Directives at the top of a SDL file #410
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
Comments
I definitely support this proposal. I've seen plenty of use cases in related languages: Headers in Thrift used for both imports and describing code generation namespacing details. https://thrift.apache.org/docs/idl#header Protobuf has a similar set of explicit grammar rules for this top level metadata https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#proto_file Capn Proto has a generic grammar similar to directives called annotations (better name IMHO, whoops) that it describes having many uses including code generation control https://capnproto.org/language.html#annotations |
If we didn't have top-level directives, you could still do a lot with type-level type Post @import(from: "./other-types.graphql") {}
type Comment @import(from: "./other-types.graphql") {} Since you're importing into the Presumably you could also rename types imported from the sub-schema, using other optional If we did have top-level directives, I imagine they would be equivalent to directives on the schema @import(...) {
query: Query
mutation: Mutation
} Either way, there's a problem here, because anyone coming from other languages will probably assume they can have more than one top-level Another problem with using directives for imports: while it makes composing SDL documents a little easier, it doesn't help you organize your resolver functions in a similar way. Because you're no longer manually creating the I'm interested in implementing imports without using comments, but I'm skeptical that directives are the way to do it. |
Hmm this definitely looks like an interesting idea, @benjamn! I've recently had a chat with @jnwng and @gagoar about the same topic. Their preferred syntax seemed to have been the following: @import(from: "./other-types.graphql" defs: [
"Post",
"Comment"
]) @jnwng @gagoar would love to hear how your thoughts have evolved. |
I definitely support the syntax that @schickling is proposing, putting the Unrelated but it's such a shame that JS ES6 follows the format of definitions followed by source... A lot of GraphQL developers may find themselves accustomed to this pattern but I feel there's no need to repeat mistakes in other languages that developers are having to constantly workaround just because it's the norm. Case in point: I find myself constantly typing JS imports in the following fashion: Step 1: import {} from 'some_source' Step 2: import { something } from 'some_source' |
OpenAPI/Swagger/JSON Schema use JSON Reference for the import case. I think import is worthy of its own syntax rather than piggybacking on directives. A GraphQL document with imports won't validate without understanding the imports, right? |
In the latest Working Group meeting Graphcool presented GraphQL Import. It was brought up that we could change the syntax to be based on directives instead of comments:
instead of
# import Post, Comment from "./other-types.graphql"
In the current spec, directives must always be placed after another node. As such, there is no way to place a directive at the top of a file. I volunteered to create an RFC to rectify this using the
@import
directive as motivation.Discussion in the issue for graphql-import let to the conclusion that import should not switch to a directive based syntax.
I still think it might be valuable to allow directives in the beginning of a file and would love to hear other use cases for this before proceeding with an RFC.
The text was updated successfully, but these errors were encountered: