-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve clarity of scalar types #597
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
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 Definitely big improvement over previous text.
Honestly I still find this section confusing/unclear regarding some details. Let me try to explain: "Internal types" is used without being clearly explained, but I think it is implicitly clear that these are the types used by the engine at execution time. Then we have two different kind of "serialization" steps happening: one is the result coercion which maps the resolved value to a serialized value for a specific scalar. This happens during the execution. Then we have a second serialization step which is described in the "Response" section and this describes how the whole result map/tree can be serialized for example to JSON. But it also makes it clear that this serialization is not clearly defined and GraphQL can be serialized to anything as long this format support List,Map,String, null primitives. So to summarize for graphql-js with JSON transport serialization we have the following table:
For Java with JSON this table looks like this:
I think we must more clearly seperate between transport serialization (which is outside of the GraphQL spec for anything except JSON) and serialization of an resolved value to an internal type (result coercion). As disccussed separetely with @leebyron scalars should probably only be coerced to primitive internal types (or recursivley Map/List of primitives). One challenge with that restriction is that the result coersion is not observable from the outside: for example a custom scalar DateTime could theorecitally be coerced to internal DateTime object and then transport serialized to a String in JSON. To summarize:
|
@andimarek I'm opposed to it since it will restrict the ability to take advantage of protocol-specific types. For example, gRPC supports file transfers and it could be represented by |
@IvanGoncharov that is the interesting part: you are right: Maybe it is more accurate to say that cross platform scalars needs (should) only be mapped to primitive internal types? Because if you don't you can't really specify any cross platform behaviour. |
For example, using the same mechanism we discussed by for
If the underlying protocol is cross-platform it means scalars are also cross-platform. Practically speaking from my experience with BTW. I think |
Let me be a bit more detailed about what I mean: In order to use a scalar (lets make our life easier here and just talk about scalars used as output) correctly you need to know what comes back. You query a field There are two different possible ways how to define Using primitive internal typesBy describing the coerced (serialized step 1) result using a primitive internal type. Meaning Using an non primitive typeLets assume Of course you can go down this route but then you have to to do exactly what you mentioned that you need a an extra "serialize this Scalar with this protocol spec". |
I think the current version of this PR is a big improvement as is. |
Agree with Ivan that this PR is a step in the right direction and should not be held up by the larger question. My two cents on the larger question: I think the talk of two separate serialization steps is a mistake, and likely not intended. Result coercion is not related to serialization IMO, it is a convenience for resolver authors. As such, scalars should not be required to serialize to one of the spec primitives, but they should be required to specify serialization behaviour in some transport(s), and their use in other transports should be considered undefined. |
bb56c71
to
c80c970
Compare
Attempts a more holistic fix to #535 which unifies language around built-in scalars and serialization, shortening the intro to this section in the process.
c80c970
to
5dad151
Compare
Attempts a more holistic fix to #535 which unifies language around built-in scalars and serialization, shortening the intro to this section in the process.