-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[RFC]: Add namedType and punctuatedName to __Type #710
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
Please change the title from |
@benjie If you have not yet, would you be willing to review the changes to the spec on this branch? I've also added myself to the May 7 wg meeting graphql/graphql-wg#393 |
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 great start @chemisus; I'm not actually sure how best to express this in spec-language so I've paged Ivan who may have a better idea.
@@ -348,6 +387,8 @@ Fields | |||
|
|||
* `kind` must return `__TypeKind.LIST`. | |||
* `ofType`: Any type. | |||
* `punctuatedName` must return `'[' + ofType.punctuatedName + ']'`. |
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.
@IvanGoncharov Using +
for string concatenation in the spec is likely not allowed since it's a cross-language specification. Do we have any examples in the spec where concatenation is used that we could apply here?
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.
Same thing goes for ofType.punctuatedName
for referencing a field of a value. I think we might have to settle for writing this in prose, awkward though this may be:
* `punctuatedName` must return `'[' + ofType.punctuatedName + ']'`. | |
* `punctuatedName` must return the result of concatenating the `[` character, the wrapped type's `punctuatedName` value, and a `]` character. |
Co-Authored-By: Benjie Gillam <[email protected]>
Co-Authored-By: Benjie Gillam <[email protected]>
(not sure it is an appropriate place to add comments about the topic, still new here) Hi everybody, I am all in favor of this addition, I think this feature is long overdue. https://github.com/rivantsov/ngraphql/blob/master/misc/UnitTestsLog.txt#L655 I would suggest to think about displayName as new field name, instead of punctuatedName, seems clearer to me, less confusing. |
e5d241d
to
6c81ed8
Compare
Problem: There are a few issues one runs into when using the introspection of a schema to get the return types of fields.
Example:
As seen, StringTable is a simple container for a string[][]. The query just to find that out would look like this:
The output of which is as follows:
All that just for just one field is unnecessary. It's even worse when viewing several fields for several types. If there were another List added for some reason, the query would need to be modified to add another level and resent. To avoid the process of modifying and resending queries, the initial query usually includes several levels to start.
Solution: I'd like to propose adding two fields to __Type:
namedType
andpunctuatedName
.namedType
returns the underlying named type, found by continually unwrapping the type until a named type is found - i.e. the type with all non-null and list wrappers removed.punctuatedName
returns the name of the (wrapped) type as it would be expressed in GraphQL's IDL; i.e. the underlying named types' name with additional punctuators from wrapping Lists and NonNulls.Depending on the type's kind,
namedType
would resolve to the following:namedType := ofType.namedType
namedType
would yield a reference to itself.Depending on the type's kind,
punctuatedName
would resolve to the following:punctuatedName := '[' + ofType.punctuatedName + ']'
punctuatedName := ofType.punctuatedName + '!'
punctuatedName := name
Adding
namedType
andpunctuatedName
to __Type would allow for the following query:Which would yield the following output:
As seen, that is a much more compact query and response. It would also guarantee to provide a return information about the fields base type or punctuated name for any given field on the first request.