You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I would like to create a custom scalar that serializes as a JSON object. @tyranron is this feasible with the v0.15 API, or are #1072 and #975 necessary for this?
I am hoping to be able to implement a GraphQL server like this:
This would work in the simple case of the Point example I gave, but the data structures I am dealing with have a complex serialization defined with serde including multiple levels of structs and enums, and I don't want to allow users of my API to attempt to query a subset of the fields, it's either all or nothing, so a scalar is the most appropriate. Is serializing JSON to a string my only option until #1072 and #975 land?
I don't want to allow users of my API to attempt to query a subset of the fields, it's either all or nothing, so a scalar is the most appropriate.
If you want to just give users a lot of data without querying subsets of it, custom scalar is your best option. I don't see how support for serde_json would help here. This integration is more for dynamic schema which isn't defined strictly with Rust types. 0.16 also will land more ergonomic scalar macros.
I guess my question is, can my custom scalar be a complex nested JSON value, which I serialize with serde?
Something like this should work now:
#[derive(Deserialize,Serialize,GraphQLScalar)]#[graphql(parse_token(String))]structMyCustomStruct{// a lot of fields...}implMyCustomStruct{fnfrom_input<S:ScalarValue>(input:&InputValue<S>,) -> Result<Self,String>{
serde_json::from_str(input.as_string_value()).map_err(|e| e.to_string())}fnto_output<S:ScalarValue>(&self) -> Value<S>{
serde_json::to_string(self).unwrap().into()}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Hi, I would like to create a custom scalar that serializes as a JSON object. @tyranron is this feasible with the v0.15 API, or are #1072 and #975 necessary for this?
I am hoping to be able to implement a GraphQL server like this:
All reactions