-
Notifications
You must be signed in to change notification settings - Fork 434
Support custom scalar types #232
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
Comments
Thanks for the investigation in this and #198 ! I don't know why, but this still seems off to me. It feels like leaking the implementation details / server language semantics into the GraphQL layer. For example, a JS client wouldn't care about i16 vs i32, yet it now needs to care because the server exposes both as scalar types. Then again, custom scalar types are essentially the server telling the client what the requirements are and the invariants that hold for that field, so maybe it is the right thing to do. I guess if we define these types in juniper consumers of the lib aren't forced to use them. They could just use the default So, I think I adding these via a feature flag that defaults to on--similar to the That being said, it sounds like we aren't really set up to handle this case based on your investigations, right? We can treat them as a |
Also see graphql/graphql-spec#326 |
From the perspective of a JS client this is looking like leaking a implementation detail, right. But who says that the Client needs to be JS (and also the transport layer needs to be http with json serialization.)
If someone does not (want) to use those types they should not be seen anywhere.
After a bit toying around I think the proper solution is to replace the scalar enum variants in |
It looks like the spec might be changing soon: graphql/graphql-spec#521 |
As far as I understood this proposal this only adds a way to specify that a custom scalar value has the same representation as an existing scalar value. This does not forbid doing something like |
This should be fixed after #251 was merged. |
I've toyed a bit around to support custom scalar values in juniper.
The following is some sort of brain dump of the current state.
Adding support for new scalar types that are mapping to existing types seems to be quite easily possible, by reusing existing enum variants in
Value
andInputValue
. Using this approach it is for example possible to add support for a 16 bit integer type, because we could simply map that to the existing 32 bit integer. On the other hand adding support for types that are not representable by the existing enum variants is not possible. (An Example here would be adding support for 64 bit integers. They would potentially cause overflows in the 32 bit integer enum variant)I see several ways to "solve" this: (I've not tried any of this so it may work or it may not work)
Add more variants to both enums. So that there is a own variant for each supported type.
This approach has several downsides:
Use other types in the existing enum variants
Again there are downsides:
i64
, but what when someone want's to represent ai128
and so onTry to make the schema generic about the exact
Value
/InputValue
type, provide a defaultValue
type (maybe the existing one) and allow users to override this typeDownsides:
I would love to here some other opinions on this before trying further to make this work in a nice way.
(This is basically the only remaining open point for wundergraph)
cc @theduke @LegNeato
Related: #198
The text was updated successfully, but these errors were encountered: