graphql-java-annotations
graphql-java-annotations copied to clipboard
How should nulls and omitted values be handled?
How can I distinguish in java graphQL if a parameter was explicitly set to null, or if it was not provided at all?
mutation {
updateProducts(products: [
{
id: "ABC"
name: null
availability: "InStock"
}
]) {
result {
errors {
field
}
}
}
}
How can I differentiate between name
being null
vs. name
being omitted? Here's my bean:
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import graphql.annotations.annotationTypes.GraphQLNonNull;
public class MyEntity {
@GraphQLField
@GraphQLName("id")
@GraphQLNonNull
public final String id;
@GraphQLField
@GraphQLName("name")
private final String name;
@GraphQLField
@GraphQLName("availability")
private final String availability;
public MyEntity(
@GraphQLNonNull
@GraphQLName("id") String id,
@GraphQLName("name") String name,
@GraphQLName("availability") String availability) {
this.id = id;
this.name = name;
this.availability = availability;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getAvailability() {
return availability;
}
}
You can receive a HashMap in the constructor which contains your arguments. Then if the argument name exists as a key in the hashmap, you know it's defined (and null in that matter)
Hi @mridang ,
We're helping with project maintenance and reviewing the list of opened PRs and Issues.
This issue was created quite a while ago, we were wondering if you were still interested in the outcome, please let us know if this is the case.
Without an answer by July 1st, 2023, this issue will be closed as "inactive" (and can always be re-opened later on if needed).
Thanks,