-
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
Proposal: Add namedType and punctuatedName to __Type #709
Comments
There is also a discussion about generics (#190) within graphql going on, isn't this a very closely related topic, as an array of T is a generic on T? If done in a generalized way this could leave some door open to extend this handling to all generic types in the future. |
@jdehaan , it looks like that discussion has been going on for four years now. Understandably so though. I believe the concept of basename and fullname to be pretty straight forward, especially when compared to generics. This is my first proposal to graphql-spec, so I'm not certain of the average duration required to move through the process. However, I would assume there is a good chance that something like this proposal could get into the spec before generics, despite it having a four year head start. I've not read through all of #190 to see which direction they are heading towards, but I'm sure both Other than that, I don't want to speak for all graphql implementations, but unless the code base is way out of whack, then it should be a fairly easy process to incorporate the fields. |
Rather than Where Secondly (and this is more of a bikeshedding suggestion) I don't think In the GraphQL spec The GraphQL spec refers to I also considered using IDL in the field name (inspired by section 3), but couldn't come up with a compelling name. I also considered using With these suggestions, the schema modifications would be: extend type __Type {
namedType: __Type!
punctuatedName: String!
} (note: both fields are non-nullable because they're guaranteed to exist for any type) and the equivalent of your query above would be: {
__type(name:"StringTable") {
kind
name
fields {
name
type {
name
namedType { name }
punctuatedName
}
}
}
} I think this proposal has value 👍 Would you like to open an RFC with some specification edits, and propose it at the next GraphQL Spec Working Group? |
@benjie , those are great suggestions! Thank you. I had similar concerns with the name of I like the |
I see what you're saying, but I think |
Sounds good. I'm on board with it. |
I've updated the proposal with your suggestions. |
Excellent! A couple final suggestions as copy edits:
Perhaps:
Perhaps:
|
Done. |
I've opened PR at #710. Will close this one. |
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.
The text was updated successfully, but these errors were encountered: