66import graphql .Internal ;
77import graphql .PublicApi ;
88import graphql .schema .DataFetcher ;
9+ import org .jspecify .annotations .NullMarked ;
10+ import org .jspecify .annotations .Nullable ;
911
1012import java .util .ArrayList ;
1113import java .util .List ;
3234 * @param <T> The type of the data fetched
3335 */
3436@ PublicApi
37+ @ NullMarked
3538public class DataFetcherResult <T > {
3639
37- private final T data ;
40+ private final @ Nullable T data ;
3841 private final List <GraphQLError > errors ;
39- private final Object localContext ;
40- private final Map <Object , Object > extensions ;
42+ private final @ Nullable Object localContext ;
43+ private final @ Nullable Map <Object , Object > extensions ;
4144
42- private DataFetcherResult (T data , List <GraphQLError > errors , Object localContext , Map <Object , Object > extensions ) {
45+ private DataFetcherResult (@ Nullable T data , List <GraphQLError > errors , @ Nullable Object localContext , @ Nullable Map <Object , Object > extensions ) {
4346 this .data = data ;
4447 this .errors = ImmutableList .copyOf (assertNotNull (errors ));
4548 this .localContext = localContext ;
@@ -49,7 +52,7 @@ private DataFetcherResult(T data, List<GraphQLError> errors, Object localContext
4952 /**
5053 * @return The data fetched. May be null.
5154 */
52- public T getData () {
55+ public @ Nullable T getData () {
5356 return data ;
5457 }
5558
@@ -72,7 +75,7 @@ public boolean hasErrors() {
7275 *
7376 * @return a local context object
7477 */
75- public Object getLocalContext () {
78+ public @ Nullable Object getLocalContext () {
7679 return localContext ;
7780 }
7881
@@ -88,7 +91,7 @@ public Object getLocalContext() {
8891 * @see graphql.extensions.ExtensionsBuilder
8992 * @see graphql.extensions.ExtensionsMerger
9093 */
91- public Map <Object , Object > getExtensions () {
94+ public @ Nullable Map <Object , Object > getExtensions () {
9295 return extensions ;
9396 }
9497
@@ -115,7 +118,7 @@ public DataFetcherResult<T> transform(Consumer<Builder<T>> builderConsumer) {
115118 *
116119 * @return a new instance with where the data value has been transformed
117120 */
118- public <R > DataFetcherResult <R > map (Function <T , R > transformation ) {
121+ public <R > DataFetcherResult <R > map (Function <@ Nullable T , @ Nullable R > transformation ) {
119122 return new Builder <>(transformation .apply (this .data ))
120123 .errors (this .errors )
121124 .extensions (this .extensions )
@@ -135,10 +138,10 @@ public static <T> Builder<T> newResult() {
135138 }
136139
137140 public static class Builder <T > {
138- private T data ;
139- private Object localContext ;
141+ private @ Nullable T data ;
142+ private @ Nullable Object localContext ;
140143 private final List <GraphQLError > errors = new ArrayList <>();
141- private Map <Object , Object > extensions ;
144+ private @ Nullable Map <Object , Object > extensions ;
142145
143146 public Builder (DataFetcherResult <T > existing ) {
144147 data = existing .getData ();
@@ -147,14 +150,14 @@ public Builder(DataFetcherResult<T> existing) {
147150 extensions = existing .extensions ;
148151 }
149152
150- public Builder (T data ) {
153+ public Builder (@ Nullable T data ) {
151154 this .data = data ;
152155 }
153156
154157 public Builder () {
155158 }
156159
157- public Builder <T > data (T data ) {
160+ public Builder <T > data (@ Nullable T data ) {
158161 this .data = data ;
159162 return this ;
160163 }
@@ -181,12 +184,12 @@ public boolean hasErrors() {
181184 return !errors .isEmpty ();
182185 }
183186
184- public Builder <T > localContext (Object localContext ) {
187+ public Builder <T > localContext (@ Nullable Object localContext ) {
185188 this .localContext = localContext ;
186189 return this ;
187190 }
188191
189- public Builder <T > extensions (Map <Object , Object > extensions ) {
192+ public Builder <T > extensions (@ Nullable Map <Object , Object > extensions ) {
190193 this .extensions = extensions ;
191194 return this ;
192195 }
0 commit comments