-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
GraphQLError.java
154 lines (134 loc) · 4.52 KB
/
GraphQLError.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package graphql;
import graphql.execution.ResultPath;
import graphql.language.SourceLocation;
import org.jetbrains.annotations.Nullable;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* The interface describing graphql errors
*
* NOTE: This class implements {@link java.io.Serializable} and hence it can be serialised and placed into a distributed cache. However we
* are not aiming to provide long term compatibility and do not intend for you to place this serialised data into permanent storage,
* with times frames that cross graphql-java versions. While we don't change things unnecessarily, we may inadvertently break
* the serialised compatibility across versions.
*
* @see <a href="https://spec.graphql.org/October2021/#sec-Errors">GraphQL Spec - 7.1.2 Errors</a>
*/
@PublicApi
public interface GraphQLError extends Serializable {
/**
* @return a description of the error intended for the developer as a guide to understand and correct the error
*/
String getMessage();
/**
* @return the location(s) within the GraphQL document at which the error occurred. Each {@link SourceLocation}
* describes the beginning of an associated syntax element
*/
List<SourceLocation> getLocations();
/**
* @return an object classifying this error
*/
ErrorClassification getErrorType();
/**
* The graphql spec says that the (optional) path field of any error must be
* a list of path entries starting at the root of the response
* and ending with the field associated with the error
* https://spec.graphql.org/draft/#sec-Errors.Error-Result-Format
*
* @return the path in list format
*/
default List<Object> getPath() {
return null;
}
/**
* The graphql specification says that result of a call should be a map that follows certain rules on what items
* should be present. Certain JSON serializers may or may interpret the error to spec, so this method
* is provided to produce a map that strictly follows the specification.
*
* See : <a href="https://spec.graphql.org/October2021/#sec-Errors">GraphQL Spec - 7.1.2 Errors</a>
*
* @return a map of the error that strictly follows the specification
*/
default Map<String, Object> toSpecification() {
return GraphqlErrorHelper.toSpecification(this);
}
/**
* @return a map of error extensions or null if there are none
*/
default Map<String, Object> getExtensions() {
return null;
}
/**
* @return a new builder of {@link GraphQLError}s
*/
static Builder<?> newError() {
return new GraphqlErrorBuilder<>();
}
/**
* A builder of {@link GraphQLError}s
*/
interface Builder<B extends Builder<B>> {
/**
* Sets the message of the error using {@link String#format(String, Object...)} with the arguments
*
* @param message the message
* @param formatArgs the arguments to use
*
* @return this builder
*/
B message(String message, Object... formatArgs);
/**
* This adds locations to the error
*
* @param locations the locations to add
*
* @return this builder
*/
B locations(@Nullable List<SourceLocation> locations);
/**
* This adds a location to the error
*
* @param location the locations to add
*
* @return this builder
*/
B location(@Nullable SourceLocation location);
/**
* Sets the path of the message
*
* @param path can be null
*
* @return this builder
*/
B path(@Nullable ResultPath path);
/**
* Sets the path of the message
*
* @param path can be null
*
* @return this builder
*/
B path(@Nullable List<Object> path);
/**
* Sets the {@link ErrorClassification} of the message
*
* @param errorType the error classification to use
*
* @return this builder
*/
B errorType(ErrorClassification errorType);
/**
* Sets the extensions of the message
*
* @param extensions the extensions to use
*
* @return this builder
*/
B extensions(@Nullable Map<String, Object> extensions);
/**
* @return a newly built GraphqlError
*/
GraphQLError build();
}
}