Skip to content

Native scalar support for json (w/ feature = "json") #280

Open
@kestred

Description

@kestred

I would like to be able to use a serde_json::Value as an Input or Output value in the graph.
This can work fine for output values, but doesn't work for Input values.

Simple-ish work arounds include newtype-ing json::Value and having it serialize as some sort of string or blob--- but that causes easily avoidable and unnecessary pain for both a Javascript Client and for the server itself (which might, for example use the same struct with both diesel and juniper).

This doesn't work (I think) because using an arbitrary JSON value as an input (or output) would require unusual handling during validation that is not described by the GraphQL spec. We could, as an extension have special handling for a serde_json::Value that does not attempt to further validate the input after identifying that the input variable / input-object field is expecting arbitrary JSON.

I believe an extension like this must be implemented within juniper itself (although if I'm wrong, I'd love to know). This should be fairly low risk to add to core, as serde_json is an incredibly widely used and well supported rust crate. Presumably it would be a off-by-default feature flag since it is an extension to the GraphQL spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions