-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fields that do not return a value #906
Comments
+1 for void |
I have had similar problems, and also went with a boolean response as a workaround. This seems like a valid addition to me. |
Would the field return null or would it have no representation in the payload? What would happen if the field threw an error? |
I think it should be 'no repr in payload', just like with 'skip(if:true)'; if error - just same stuff, error object should appear in errors, path should include the field name at the end, don't see any problem with that |
I really like the idea of having no representation in the payload, and it is great to see that there is already an existing construct that does the same. This seems good for schema evolution: with the field not being present at all, clients will very likely have no code that somehow depends on the result (which might be the case with any pseudo-value). Then, it is easier to introduce any return type once the field has evolved to actually provide useful information. What would be the best representation in introspection? A very simple solution would be for the field to have no return type at all, thus letting |
@spawnia, one option would be to do like c#: |
@spawnia The selection set validation rules would have to be modified to allow changing from void with no selection set to an object payload type with selection set. One option is to use an “empty” object type, but this comes with a bunch of caveats:
I don’t see a clear path for this kind of schema evolution. 😔 |
Motivation
Our application defines some mutations that are purely used to trigger side effects and don't return a value.
GraphQL enforces the definition of a return type for those fields. Due to this constraint and lack of a better alternative, I have found all of the following permutations to be present in our codebase:
Boolean!
, resolver always returnstrue
Boolean!
, resolver returns a boolean indicating success - swallowing errors!Boolean
, resolver is defined to returnvoid
, result is serialized tonull
While this inconsistency is not pretty for someone on the server side, it is especially bad for the client. Depending on the quality of the schema documentation, they won't know for sure if the return type is meaningful.
Idea
Introduce an idiomatic way to represent the notion of a field that returns no value.
Possible Solutions
No Type
Allow defining the field with no return type at all.
__Field.type
nullable in introspectionIt is unclear to me how this field would be represented in the serialized result, given it is a map and there has to be something in the place of the value. Perhaps
null
?void
Introduce a new keyword
void
that acts as a pseudo-type.Unit Type
Introduce a new type
Unit
that allows only one possible value and thus can hold no information.Some rules:
Unit
is implicitly non-nullable, otherwise the value could benull
or whatever the representation ofUnit
isUnit
can not be used in listsBuilding upon existing types, I can see the definition of this type being either one of:
UNIT
UNIT
I can see this type being useful as an argument too, enabling a binary toggle between not passing the argument at all or passing it.
The text was updated successfully, but these errors were encountered: