graphql-rust / juniper

GraphQL server library for Rust
Other
5.72k stars 425 forks source link

Input type, determine if key set or unset #1238

Closed Compulsed closed 10 months ago

Compulsed commented 10 months ago

Is your feature request related to a problem? Please describe. Would like to be able to determine if the key has been explicitly set to null, OR is not included. This functionality is useful for performing partial updates. At the moment (options below), 2/ & 3/ are represented as as None.

When working with GraphQL / JSON there are three states:

  1. Key/Value is set. {"name": "Frank"}
  2. Key is set, value is null. {"name": null}
  3. Neither the key or value is set {}

Describe the solution you'd like Would like to have a custom InputScalar which is a enum type

struct InputType {
   Set(T) // 1
   None, // 2
   NotSpecified // 3
}

Describe alternatives you've considered Another option might be to surface this up as some kind of dictionary type, though, I think this would be difficult because the Input types are used to generate the GraphQL schema.

Additional context Let me know if anyone has a custom solution, I am not sure how I would be able to achieve this (even if it is possible) with the existing custom scalar functionality.

https://graphql-rust.github.io/juniper/master/types/scalars.html

tyranron commented 10 months ago

@Compulsed sorry for a bit late reply on this.

We have Nullable enum for distinguishing between explicit and implicit nulls. It's also covered in the "Implicit and explicit null" chapter of the Book.

Compulsed commented 10 months ago

@tyranron -- this is exactly what I was looking for. Thank you for point this out!