forked from graphql-java/graphql-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NonNullableValueCoercedAsNullException.java
93 lines (77 loc) · 3.99 KB
/
NonNullableValueCoercedAsNullException.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package graphql.execution;
import graphql.ErrorType;
import graphql.GraphQLError;
import graphql.GraphQLException;
import graphql.PublicApi;
import graphql.language.SourceLocation;
import graphql.language.VariableDefinition;
import graphql.schema.GraphQLArgument;
import graphql.schema.GraphQLInputObjectField;
import graphql.schema.GraphQLType;
import graphql.schema.GraphQLTypeUtil;
import java.util.Collections;
import java.util.List;
import static java.lang.String.format;
/**
* This is thrown if a non nullable value is coerced to a null value
*/
@PublicApi
public class NonNullableValueCoercedAsNullException extends GraphQLException implements GraphQLError {
private List<SourceLocation> sourceLocations;
private List<Object> path;
public NonNullableValueCoercedAsNullException(VariableDefinition variableDefinition, GraphQLType graphQLType) {
super(format("Variable '%s' has coerced Null value for NonNull type '%s'",
variableDefinition.getName(), GraphQLTypeUtil.simplePrint(graphQLType)));
this.sourceLocations = Collections.singletonList(variableDefinition.getSourceLocation());
}
public NonNullableValueCoercedAsNullException(VariableDefinition variableDefinition, String fieldName, GraphQLType graphQLType) {
super(format("Field '%s' of variable '%s' has coerced Null value for NonNull type '%s'",
fieldName, variableDefinition.getName(), GraphQLTypeUtil.simplePrint(graphQLType)));
this.sourceLocations = Collections.singletonList(variableDefinition.getSourceLocation());
}
public NonNullableValueCoercedAsNullException(VariableDefinition variableDefinition, String fieldName, List<Object> path, GraphQLType graphQLType) {
super(format("Field '%s' of variable '%s' has coerced Null value for NonNull type '%s'",
fieldName, variableDefinition.getName(), GraphQLTypeUtil.simplePrint(graphQLType)));
this.sourceLocations = Collections.singletonList(variableDefinition.getSourceLocation());
this.path = path;
}
public NonNullableValueCoercedAsNullException(List<Object> path, GraphQLType graphQLType) {
super(format("Coerced Null value for NonNull type '%s'",
GraphQLTypeUtil.simplePrint(graphQLType)));
this.path = path;
}
public NonNullableValueCoercedAsNullException(VariableDefinition variableDefinition, String causeMessage) {
super(format("Variable '%s' has invalid value: %s",
variableDefinition.getName(), causeMessage));
this.sourceLocations = Collections.singletonList(variableDefinition.getSourceLocation());
}
public NonNullableValueCoercedAsNullException(String fieldName, List<Object> path, GraphQLType graphQLType) {
super(format("Field '%s' has coerced Null value for NonNull type '%s'",
fieldName, GraphQLTypeUtil.simplePrint(graphQLType)));
this.path = path;
}
public NonNullableValueCoercedAsNullException(GraphQLInputObjectField inputTypeField) {
super(format("Input field '%s' has coerced Null value for NonNull type '%s'",
inputTypeField.getName(), GraphQLTypeUtil.simplePrint(inputTypeField.getType())));
}
public NonNullableValueCoercedAsNullException(GraphQLInputObjectField inputTypeField, List<Object> path) {
super(format("Input field '%s' has coerced Null value for NonNull type '%s'",
inputTypeField.getName(), GraphQLTypeUtil.simplePrint(inputTypeField.getType())));
this.path = path;
}
public NonNullableValueCoercedAsNullException(GraphQLArgument graphQLArgument) {
super(format("Argument '%s' has coerced Null value for NonNull type '%s'", graphQLArgument.getName(), graphQLArgument.getType()));
}
@Override
public List<SourceLocation> getLocations() {
return sourceLocations;
}
@Override
public List<Object> getPath() {
return path;
}
@Override
public ErrorType getErrorType() {
return ErrorType.ValidationError;
}
}