-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
InputValueWithState.java
91 lines (74 loc) · 2.32 KB
/
InputValueWithState.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
package graphql.schema;
import graphql.PublicApi;
import graphql.language.Value;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static graphql.Assert.assertNotNull;
/**
* Used by @{@link GraphQLArgument} and {@link GraphQLInputObjectField} to represent different value states.
*/
@PublicApi
public class InputValueWithState {
private enum State {
/**
* Value was never set aka not provided
*/
NOT_SET,
/**
* The value is an Ast literal
*/
LITERAL,
/**
* The value is an external value
*/
EXTERNAL_VALUE,
/**
* This is only used to preserve backward compatibility (for now): it is a value which is assumed to
* be already coerced.
* This will be removed at one point.
*/
INTERNAL_VALUE
}
private final State state;
private final Object value;
private InputValueWithState(State state, Object value) {
this.state = state;
this.value = value;
}
public static final InputValueWithState NOT_SET = new InputValueWithState(State.NOT_SET, null);
public static InputValueWithState newLiteralValue(@NotNull Value value) {
assertNotNull(value, () -> "value literal can't be null");
return new InputValueWithState(State.LITERAL, value);
}
public static InputValueWithState newExternalValue(@Nullable Object value) {
return new InputValueWithState(State.EXTERNAL_VALUE, value);
}
public static InputValueWithState newInternalValue(@Nullable Object value) {
return new InputValueWithState(State.INTERNAL_VALUE, value);
}
public @Nullable Object getValue() {
return value;
}
public boolean isNotSet() {
return state == State.NOT_SET;
}
public boolean isSet() {
return state != State.NOT_SET;
}
public boolean isLiteral() {
return state == State.LITERAL;
}
public boolean isExternal() {
return state == State.EXTERNAL_VALUE;
}
public boolean isInternal() {
return state == State.INTERNAL_VALUE;
}
@Override
public String toString() {
return "InputValueWithState{" +
"state=" + state +
", value=" + value +
'}';
}
}