-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Default Root Op type names: removed duplicate statement; clarified that only Query type required #978
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
Conversation
…nly Query type is required.
✅ Deploy Preview for graphql-spec-draft ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
The first sentence is talking about a schema built from SDL. The second sentence is talking about converting an existing schema into SDL. The directions are reversed SDL to schema vs schema to SDL. This explains the can vs should: The first line says that SDL used to build a schema can opt to not specify the default values. That is simply a statement of fact, the schema will be the same whether the default values are specified or not. The second line says that an SDL representation of an existing schema (generated from an existing schema) should not necessarily specify the default values. Note that “should” is used rather than “must” so it would still be spec compliant to specify them. The spec does not say why they should not be specified, but my guess is that it beneficial to have a canonical way to represent an existing schema, and so the spec simply has to recommend something. In my opinion, the room for improvement is not to remove the line, but rather to explain the use of “should.” Although there are many places in the graphql spec, as in other specifications, where reasons for the choice of can vs should vs must would be helpful to me… |
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 think the sentence was very clear before, but now is confusing to read.
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.
My previous comment on this was:
This is a concrete change in the interpretation of the GraphQL specification - the previous paragraph says that you can define a schema like this:
type Query { ... } schema { query: Query }or, equivalently, like this:
type Query { ... }The paragraph you have deleted does not state the same thing again, it states the converse: when a GraphQL schema is represented via SDL (rather than defined by it; i.e. when you do
printSchema(schema)
in GraphQL.js or equivalent in other languages) you should omit theschema
keyword under these circumstances.
I don't think the sentence you have added is a substitute for the paragraph you have deleted, and I believe the existing spec text is perfectly fine.
I favour no change.
@benjie and all I believe there's some confusion here, and it's my fault, it smashed two enhancements in one. The sentence I added ("This rule applies also...") - this is NOT a replacement for the 'duplicate' second sentence that I removed. It addresses a separate issue. From the current text about skipping the schema def, it is not clear if I have to define all 3 types (Query, Mutation, Subscription) to make skipping schema element possible, or I can define just Query, like in @benjie's example above. It actually reads like you have to define all three. I believe this clarification is necessary - that only Query is enough. My wording might not be perfect, it is not - no problem, suggest something better. |
@rivantsov Good spot, there's actually a bit more ambiguity there; I've raised an alternative pull request at #987 which addresses this. |
@benjie et al
as far as I understood (finally), the key here is the word 'should' - I initially thought it's a mistake, a typo. But now I see, and it makes the whole meaning is even more 'strange'. What it says is: 'when SDL file is generated by a server/framework like graphql.js, the generator SHOULD omit schema element if default op names are used'. Short version: if something is optional and CAN be omitted, it SHOULD be omitted . This sounds REALLY strange. Like for fields with optional args it would look like this, if you follow this rule. # field with arg
type MyType {
myField (arg: Int = 5) : Int
}
# queries
myField(arg: 3) # ok
myField # ok, default value 5 will be used
myField(arg: 5) # wrong! error! if it can be omitted, it should be omitted! Does it look reasonable? I think not. Not here, not with 'schema' element. It is up to the implementing framework/dev to omit or not - as long as the resulting file is valid - which it is. Just because graphql.js is doing it this way (always omitting) - it is not a reason to force it on everybody out there. And by the way, there might be reasons to still define 'schema' element explicitly - for ex, there might be a directive defined on schema or its fields (query, mutation) - what to do then? (as far as I understand, dir location enum allows this). So my suggestion - drop this 'should' requirement, it is unusual and unreasonable, and then the need for this second sentence goes away. Thank you |
If you do not implement a should your implementation is still valid. So, it is up to the implementor to decide on this aspect. In general the should leads to a cleaner SDL but it still up to you to implement the should. |
Let me attempt to explain this using my revised wording in #987. Server
This means: "when you are defining a GraphQL schema using SDL you don't need to add the const sdl = `
type Query {
xkcd221: Int
}
`;
const resolvers = {
Query: {
xkcd221() {
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
}
};
export const schema = makeSchema(sdl, resolvers); or it could be const sdl = `
type Query {
xkcd221: Int
}
schema {
query: Query
}
`;
// ... The specification doesn't care either way - they're equivalent as far as it's concerned, the details are lost as soon as the schema is built so it's irrelevant, hence the use of No matter which option I choose, I have constructed an identical GraphQL schema. Let's imagine I use something like ClientNow, I use my client, GraphiQL, to introspect the schema. It issues the query
So the client will render to the user: type Query {
xkcd221: Int
} It won't add |
Again, sorry for the delay in response. Stuff keeps happening. I really appreciate your detailed responses, guys. @michaelstaib
Meaning: we RECOMMEND this way, and you must have damn good reasons not to follow. That's too much. Why should I look for strong reasons to follow the path (add an explicit small schema element) that is absolutely valid in terms of the resulted doc? We (WG and spec) better simply RECOMMEND, at most - use this word instead of 'should'. @benjie,
is equivalent to
Well, I think this is a really wrong assumption. For a newcomer, the first (current) version is hell confusing, to the level of 'wtf does this mean?'. When we 'represent' rather than 'define'?! That's my BIG problem with this sentence. So, to sum it up, my suggestion(s) are still, either
Likewise, when the GraphQL schema file is generated by a tool or software, it is recommended to omit the schema element if ... |
I think it should be recommended because it makes GraphQL schemas represented as SDL more consistent across different vendors. Following the recommendations of the spec, whitespace aside, the same GraphQL schema should have the same representation in SDL independent of the tooling used to generate it. (Same type order, same field order, same descriptions, same deprecations, same arguments in order, same directives in order, etc etc etc.)
That's not the full story - it's not specific to generating a "file", it's not limited to when using "a tool or some software" (it could be hand written), and it's specifically talking about representing a GraphQL schema that already exists. So a more full definition expanding on yours would be "when type system definition language is generated by a tool or some software or some other process to represent an existing GraphQL schema" Since the process that triggers the TSDL to be generated is unimportant (it's any cause that means we're representing a GraphQL schema in TSDL), we can shorten this to: "when the type system definition language is used to represent a GraphQL schema" We could rewrite that a little to give "when representing a GraphQL schema using the type system definition language." At this point we've come full circle. I prefer this final wording as the most straightforward and accurate without unnecessary narrowing of use-cases. |
Same types order? where the spec says it that types should be printed in some specific order? For introspection API, __Schema.types is defined as a set, without any specific order. Then, in what sense is it even possible to have 'the same' representation for different tools, if there's no specified order for anything? They will be equivalent, but textually quite different. You mention 'same arguments in order' - which order if spec specifically says that 'order of args is not important/irrelevant' ? |
Closing this PR |
Default Root Op type names: removed duplicate statement, added that only Query type is required.
@benjie argued previously that the second sentence (starting with Likewise...) is not a duplicate, it's different, but its seems abs repeat for me. Except 'should omit' instead of 'can omit' - which I think is incorrect. If you have an optional arg with default value, you do not require it to be skipped if the explicit value is the same as default value.