Correct way to handle unstructured property values
See original GitHub issueHi,
First of all, I´d like to thank you for the awesome job you have done with the spec and this reference implementation. It took only couple of hours to build a GraphQL “proxy” server by generating GraphQL schema from a preexisting JSON schema definition we had for our REST API and I’m already experiencing the benefits.
The only question I have is this; We have some abstract field types in our api. For example some responses may contain user supplied JSON metadata. This means I’m unable to define the actual fields and types for the data. Currently I’m using an ugly way to handle these fields by creating a scalar type and using that for the metadata fields.
var GraphQLAnything = new GraphQLScalarType({
name: 'Anything',
coerce: function (value) {
return value;
},
coerceLiteral: function (ast) {
return ast.value;
}
});
This works as desired (I’m able to receive the data in correct form) but defining something like this as a scalar feels wrong in so many levels. Especially as the spec says that “Scalars cannot have fields.”. Is there a correct way to handle these type of values?
Thanks!
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (4 by maintainers)
@orktes could you provide an example of how you are trying to use this with a query? I tried doing something similar but cannot seem to figure out how to format the query.
Thanks for the quick answer!
“DangerousUserProvidedUnstructuredJSON” inspired me to find a way to convert the old unstructured data into something structured 😄
Closing…