-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[RFC] Custom Scalar Specification URLs #649
Conversation
Relates to #633 |
@@ -146,6 +146,9 @@ type __Type { | |||
|
|||
# should be non-null for NON_NULL and LIST only, must be null for the others | |||
ofType: __Type | |||
|
|||
# should be non-null for SCALAR only, must be null for the others | |||
specifiedBy: String |
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.
It correlates to some extent with #300 .
If this extension of the introspection schema will be added, it is logical to expect that the proposed in #300 extension
should be also accepted. Now there is a second server directive besides @deprecated
, which is provided through introspection as a special property. I have nothing against this, but I believe that we need to provide a way to get user directives through introspection too. It will be a consistent step.
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.
@sungam3r there are some experiments on introspection extensions. Technically you can already today extend introspection but this alway comes with the danger that you violate a future specification.
@IvanGoncharov was experimenting on this one with GraphQL-js. At the moment you can put metadata on almost everything there. We do almost the same with hot chocolate. The next thing would be to allow to have something like extensions on introspection so that there is a point where you can cleanly extend the introspection types.
Doing this through directives brings some challenges since directives, specifically their arguments are input types that could bear challenges to automatically extend the introspection from those.
@IvanGoncharov maybe we should start a new discussion on that?
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 have a separate graphql-dotnet branch in which directives are already returned via introspection. We use this forked preview version in production.
this alway comes with the danger that you violate a future specification.
I agree. It’s not scary for us. We need new features now, and not when they (possibly) appear in the specification.
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.
@sungam3r i did mean that more from them perspective. Hc allows extending the introspection already for a couple of versions. But the user that does that has to know that he/she might violate a future spec. We just have a warning in the docs that you can do it but may run into an issue in the future.
spec/Section 3 -- Type System.md
Outdated
```graphql example | ||
scalar Time | ||
scalar Url | ||
scalar Time @specified(by: "https://tools.ietf.org/html/rfc3339") |
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 a bit "misleading" example because RFC3339 is normally used to describe date and time.
How about scalar DateTime @specified(by: "https://example.com/myDateTime")
?
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.
Using a non RFC link would also make it more clear that it is totally fine to come up with your scalar spec.
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 we all agreed to have a specific spec for datetime since it is based on the rfc but more narrow in its implementation. There should be a specific document outlining the rules for this 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.
Yeah, I might just take this out as an example until we have something more useful to link to.
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.
Actually, if I take it out it gets even more confusing because the other example to talk about in the paragraph above is URL and then it gets really hard to parse whether I'm talking about the URL
scalar as an example, or the URL that you provide in the example to link to the specification.
I'll rename this to DateTime
for now, with the expectation that when Andi's restricted datetime scalar format doc gets published we'll change the link to that.
spec/Section 4 -- Introspection.md
Outdated
@@ -232,13 +235,16 @@ actually valid. These kinds are listed in the `__TypeKind` enumeration. | |||
|
|||
Represents scalar types such as Int, String, and Boolean. Scalars cannot have fields. | |||
|
|||
A GraphQL type designer should describe the data format and scalar coercion | |||
rules in the description field of any scalar. | |||
A GraphQL type designer should provide use the `@specified` directive to provide |
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.
typo: should use the
great work @eapache |
spec/Section 3 -- Type System.md
Outdated
@@ -343,9 +343,17 @@ client-specific primitive for time. Another example of a potentially useful | |||
custom scalar is `Url`, which serializes as a string, but is guaranteed by | |||
the server to be a valid URL. | |||
|
|||
When defining an additional scalar, GraphQL systems should use the `@specified` | |||
directive to provide an RFC3986-compliant URI pointing to a human-readable |
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 throughout we can replace RFC3986-compliant URI
with just URL
RFC3986-compliant URI
could be understood to include an ISBN for an academic paper or something like that, and the goal here is that a person can load this URL in a browser and go read the spec. URL
is well understood with a single definition, so there's no need to qualify it further with which IETF RFC you're referring to.
This in an implementation for a spec proposal: * Spec proposal: [[RFC] Custom Scalar Specification URIs](graphql/graphql-spec#649) * Original issue: [[RFC] Custom Scalar Specification URIs](graphql/graphql-spec#635) Please let me know if I forgot something.
This in an implementation for a spec proposal: * Spec proposal: [[RFC] Custom Scalar Specification URIs](graphql/graphql-spec#649) * Original issue: [[RFC] Custom Scalar Specification URIs](graphql/graphql-spec#635)
spec/Section 4 -- Introspection.md
Outdated
@@ -146,6 +146,9 @@ type __Type { | |||
|
|||
# should be non-null for NON_NULL and LIST only, must be null for the others | |||
ofType: __Type | |||
|
|||
# should be non-null for SCALAR only, must be null for the others |
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.
Nitpick: Currently in my draft for the reference implementation graphql/graphql-js#2276, if you don't add the @specified
directive to a scalar, specifiedBy
will be null
.
If that's the correct implementation, then perhaps this wording could be updated to something along the lines of:
# should be non-null for SCALAR only, must be null for the others | |
# should be a string or null for SCALAR only, must be null for the others |
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.
Hmm, it's a good point but I think I'd prefer just replacing should
with can
or may
.
d8ed061
to
f72a146
Compare
spec/Section 3 -- Type System.md
Outdated
scalar Time | ||
scalar Url | ||
scalar UUID @specified(by: "https://tools.ietf.org/html/rfc4122") | ||
scalar URL @specified(by: "https://tools.ietf.org/html/rfc3986") |
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.
@leebyron I changed the capitalization here from Url
to URL
because Uuid
looked particularly gross, and the built-in is already ID
not Id
. It's a minor editorial thing but it's not really related to this RFC so I wanted to make sure it was ok.
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.
Seems totally fine to me
spec/Section 4 -- Introspection.md
Outdated
|
||
Fields | ||
|
||
* `kind` must return `__TypeKind.SCALAR`. | ||
* `name` must return a String. | ||
* `specifiedBy` may return a URL or {null}. |
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.
We don't have a URL
type so it should be String
.
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.
maybe may return a String (in the form of a URL) or {null}.
?
@eapache bikeshedding: How about changing
|
+1 for This is a personal feelings, |
I'm weakly in favour of |
relevant IETF specifications. | ||
|
||
```graphql example | ||
scalar UUID @specifiedBy(url: "https://tools.ietf.org/html/rfc4122") |
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.
While implementing this in graphql/graphql-js#2276 @IvanGoncharov provided the following comment:
If at some point we decide to add
UUID
scalar into this library it would be a confusing example.
It's better to use some abstract scalar likeFoo
andhttps://example.com/foo_spec
.
Question: Do we want to make that same change here as well? If so this likely applies to URL
as well, and effects a few locations in this PR.
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.
Point taken that it could become confusing, but it's not confusing yet, and there is definitely value in having a concrete example that lines up with use cases a lot of actual developers will run into. I'm planning to leave this as is, and we can change it if becomes an issue later.
This in an implementation for a spec proposal: * Spec proposal: [[RFC] Custom Scalar Specification URIs](graphql/graphql-spec#649) * Original issue: [[RFC] Custom Scalar Specification URIs](graphql/graphql-spec#635)
I've been working on the [implementation](graphql/graphql-js#2276) of the `@specified(by: "")` directive as specified by graphql/graphql-spec#649, and am interested an any feedback or progress on that effort.
Reviewing graphql/graphql-js#2276 I saw another argument for naming argument |
I've been working on the [implementation](graphql/graphql-js#2276) of the `@specified(by: "")` directive as specified by graphql/graphql-spec#649, and am interested an any feedback or progress on that effort.
1758a1c
to
cb92ed5
Compare
Co-Authored-By: Lee Byron <lee@leebyron.com>
c2e404e
to
318b753
Compare
One last follow up to #649 RFC, this uses the new term definition syntax and ensures the term usage is consistent throughout the document. Also makes a minor editorial change in the introspection section to list the `description` field under `name` like the other sections
One last follow up to #649 RFC, this uses the new term definition syntax and ensures the term usage is consistent throughout the document. Also makes a minor editorial change in the introspection section to list the `description` field under `name` like the other sections
This PR contains the specification changes needed for #635.