|
1 | 1 | package graphql; |
2 | 2 |
|
3 | 3 |
|
| 4 | +import graphql.execution.ResultPath; |
4 | 5 | import graphql.language.SourceLocation; |
| 6 | +import org.jetbrains.annotations.Nullable; |
5 | 7 |
|
6 | 8 | import java.io.Serializable; |
7 | 9 | import java.util.List; |
@@ -66,5 +68,85 @@ default Map<String, Object> getExtensions() { |
66 | 68 | return null; |
67 | 69 | } |
68 | 70 |
|
| 71 | + /** |
| 72 | + * @return a new builder of {@link GraphQLError}s |
| 73 | + */ |
| 74 | + static Builder<?> newError() { |
| 75 | + return new GraphqlErrorBuilder<>(); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * A builder of {@link GraphQLError}s |
| 80 | + */ |
| 81 | + interface Builder<B extends Builder<B>> { |
| 82 | + |
| 83 | + /** |
| 84 | + * Sets the message of the error using {@link String#format(String, Object...)} with the arguments |
| 85 | + * |
| 86 | + * @param message the message |
| 87 | + * @param formatArgs the arguments to use |
| 88 | + * |
| 89 | + * @return this builder |
| 90 | + */ |
| 91 | + B message(String message, Object... formatArgs); |
69 | 92 |
|
| 93 | + /** |
| 94 | + * This adds locations to the error |
| 95 | + * |
| 96 | + * @param locations the locations to add |
| 97 | + * |
| 98 | + * @return this builder |
| 99 | + */ |
| 100 | + B locations(@Nullable List<SourceLocation> locations); |
| 101 | + |
| 102 | + /** |
| 103 | + * This adds a location to the error |
| 104 | + * |
| 105 | + * @param location the locations to add |
| 106 | + * |
| 107 | + * @return this builder |
| 108 | + */ |
| 109 | + B location(@Nullable SourceLocation location); |
| 110 | + |
| 111 | + /** |
| 112 | + * Sets the path of the message |
| 113 | + * |
| 114 | + * @param path can be null |
| 115 | + * |
| 116 | + * @return this builder |
| 117 | + */ |
| 118 | + B path(@Nullable ResultPath path); |
| 119 | + |
| 120 | + /** |
| 121 | + * Sets the path of the message |
| 122 | + * |
| 123 | + * @param path can be null |
| 124 | + * |
| 125 | + * @return this builder |
| 126 | + */ |
| 127 | + B path(@Nullable List<Object> path); |
| 128 | + |
| 129 | + /** |
| 130 | + * Sets the {@link ErrorClassification} of the message |
| 131 | + * |
| 132 | + * @param errorType the error classification to use |
| 133 | + * |
| 134 | + * @return this builder |
| 135 | + */ |
| 136 | + B errorType(ErrorClassification errorType); |
| 137 | + |
| 138 | + /** |
| 139 | + * Sets the extensions of the message |
| 140 | + * |
| 141 | + * @param extensions the extensions to use |
| 142 | + * |
| 143 | + * @return this builder |
| 144 | + */ |
| 145 | + B extensions(@Nullable Map<String, Object> extensions); |
| 146 | + |
| 147 | + /** |
| 148 | + * @return a newly built GraphqlError |
| 149 | + */ |
| 150 | + GraphQLError build(); |
| 151 | + } |
70 | 152 | } |
0 commit comments