-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[RFC] Document Directives #556
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
base: main
Are you sure you want to change the base?
Conversation
37cbfc9
to
3a86550
Compare
spec/Section 2 -- Language.md
Outdated
|
||
```graphql example | ||
@import(from: "./common") | ||
@import(from: "./user") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use @import
directives as an example here.
Since some readers can think it a standard one and supported by GraphQL spec.
I think it would be better to use something like @someTopLevelDirective
, @foo
, @test
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is most relevant example I wish to show and indeed it is my intent to push on some common way to do import. I can add note or warning below that import is not built-in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @import
will have meaning in a bunch of libraries almost immediately, and those meaning will probably immediately diverge, let's keep it out of the spec entirely. There aren't any descriptions of any other user-level directives in the spec.
The only other usage is @addedDirective
and @example
because they illustrate the usage without introducing a new concept.
In this case, you could call it @exampleDocumentDirective
or even just @example
spec/Section 2 -- Language.md
Outdated
``` | ||
|
||
Unknown directives may be ignored, but it is recommended for services to fail | ||
if directive is not recognized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@langpavel It contradicts rules for all other directives:
https://facebook.github.io/graphql/June2018/#sec-Directives-Are-Defined
Personally, I think we shouldn't have any exceptions for top-level directives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this sentence can be dropped entirely, ok?
@@ -94,10 +94,14 @@ lines and uniform indentation with {BlockStringValue()}. | |||
Document : Definition+ | |||
|
|||
Definition : | |||
- DocumentDirective |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- DocumentDirective | |
- DocumentDirectives |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, DocumentDirective
(singular) is really what should be stated in grammar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now
Then I think it makes more sense to do
Document: Directives[Const] Definition+
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will prevent you from inserting document level directives into middle of document.
This may be problematic if you concatenate more documents into one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover there is chicken egg problem, when you wish define document directive you cannot use it in same document
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover there is chicken egg problem, when you wish define document directive you cannot use it in same document
You can. Why not?
GraphQL doesn't care about order of things in SDL. This is perfectly valid:
scalar SomeScalar @someDirective
directive @someDirective on SCALAR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you are right…
spec/Section 2 -- Language.md
Outdated
@@ -1094,3 +1095,24 @@ and operations. | |||
|
|||
As future versions of GraphQL adopt new configurable execution capabilities, | |||
they may be exposed via directives. | |||
|
|||
|
|||
## Document Directives |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think they should be a special case of directives.
They should be covered by: https://facebook.github.io/graphql/June2018/#sec-Language.Directives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intent is place document level directives aside from others, there apply different rules:
- Document directives may be repeated, others not.
- Document level directives are top level AST Document
DocumentNode.definitions
nodes, other directives are listed inXxxNode.directives
— this may need discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document directives may be repeated, others not.
#472 add support of reputable directives.
Document level directives are top level AST Document DocumentNode.definitions nodes, other directives are listed in XxxNode.directives — this may need discussion
I think DocumentNode.directives
makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd much rather see this compose with the repeatable directives change.
Moreover, even if we never gained repeatable directives, document-level driectives (such as @import
) could always be expanded to take lists instead @imports(from: ["foo", "bar/baz"])
. It's better to keep the total number of concepts down: if something looks like it should work in two contexts, but subtly works a different way in one of them, that's a spec bug.
I think we need to have a separator between top-level directives and rest of SDL file
Similar to YAML: https://yaml.org/spec/1.1/#YAML%20directive/ Because without it we can cause some confusion:
Plus I saw some people concatenate SDL files so if you have two files like this:
and
We would get valid SDL:
But parser will parse
The parser will error saying you can't use If we decide to allow top-level directives we can always allow:
|
Hmm, good point with grammar ambiguity, however I don't like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's another question: most directives are either executable
or schema
directives: you can't use a schema-level directive inside an executable document, and vice versa. Which of these is the document directive? Is it neither? Why?
Basically: if I have a document with a bunch of fragments, should I be able to include a directive that modifies the schema? Why or why not?
spec/Section 2 -- Language.md
Outdated
@@ -1094,3 +1095,24 @@ and operations. | |||
|
|||
As future versions of GraphQL adopt new configurable execution capabilities, | |||
they may be exposed via directives. | |||
|
|||
|
|||
## Document Directives |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd much rather see this compose with the repeatable directives change.
Moreover, even if we never gained repeatable directives, document-level driectives (such as @import
) could always be expanded to take lists instead @imports(from: ["foo", "bar/baz"])
. It's better to keep the total number of concepts down: if something looks like it should work in two contexts, but subtly works a different way in one of them, that's a spec bug.
spec/Section 2 -- Language.md
Outdated
|
||
```graphql example | ||
@import(from: "./common") | ||
@import(from: "./user") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @import
will have meaning in a bunch of libraries almost immediately, and those meaning will probably immediately diverge, let's keep it out of the spec entirely. There aren't any descriptions of any other user-level directives in the spec.
The only other usage is @addedDirective
and @example
because they illustrate the usage without introducing a new concept.
In this case, you could call it @exampleDocumentDirective
or even just @example
Changes made make it no longer applicable
e5d241d
to
6c81ed8
Compare
This addresses #410 Directives at the top of a SDL file
WIP
✔️ Required grammar and introspection changes included