11package graphql .validation ;
22
3-
43import graphql .Assert ;
54import graphql .Internal ;
65import graphql .execution .TypeFromAST ;
3332import graphql .schema .GraphQLUnionType ;
3433import graphql .schema .GraphQLUnmodifiedType ;
3534import graphql .schema .InputValueWithState ;
35+ import org .jspecify .annotations .NullMarked ;
36+ import org .jspecify .annotations .Nullable ;
3637
3738import java .util .ArrayList ;
3839import java .util .List ;
4344import static graphql .schema .GraphQLTypeUtil .unwrapOne ;
4445
4546@ Internal
47+ @ NullMarked
4648public class TraversalContext implements DocumentVisitor {
4749 private final GraphQLSchema schema ;
4850 private final List <GraphQLOutputType > outputTypeStack = new ArrayList <>();
@@ -51,8 +53,8 @@ public class TraversalContext implements DocumentVisitor {
5153 private final List <InputValueWithState > defaultValueStack = new ArrayList <>();
5254 private final List <GraphQLFieldDefinition > fieldDefStack = new ArrayList <>();
5355 private final List <String > nameStack = new ArrayList <>();
54- private GraphQLDirective directive ;
55- private GraphQLArgument argument ;
56+ private @ Nullable GraphQLDirective directive ;
57+ private @ Nullable GraphQLArgument argument ;
5658
5759
5860 public TraversalContext (GraphQLSchema graphQLSchema ) {
@@ -187,7 +189,7 @@ private void enterImpl(ObjectField objectField) {
187189 addDefaultValue (inputField != null ? inputField .getInputFieldDefaultValue () : null );
188190 }
189191
190- private GraphQLArgument find (List <GraphQLArgument > arguments , String name ) {
192+ private @ Nullable GraphQLArgument find (List <GraphQLArgument > arguments , String name ) {
191193 for (GraphQLArgument argument : arguments ) {
192194 if (argument .getName ().equals (name )) {
193195 return argument ;
@@ -245,23 +247,23 @@ private boolean isEmpty(String name) {
245247 return name == null || name .isEmpty ();
246248 }
247249
248- private GraphQLNullableType getNullableType (GraphQLType type ) {
250+ private @ Nullable GraphQLNullableType getNullableType (@ Nullable GraphQLType type ) {
249251 return (GraphQLNullableType ) (isNonNull (type ) ? unwrapOne (type ) : type );
250252 }
251253
252254 /**
253255 * @return can be null if current node does not have a OutputType associated: for example
254256 * if the current field is unknown
255257 */
256- public GraphQLOutputType getOutputType () {
258+ public @ Nullable GraphQLOutputType getOutputType () {
257259 return lastElement (outputTypeStack );
258260 }
259261
260- private void addOutputType (GraphQLOutputType type ) {
262+ private void addOutputType (@ Nullable GraphQLOutputType type ) {
261263 outputTypeStack .add (type );
262264 }
263265
264- private <T > T lastElement (List <T > list ) {
266+ private <T > @ Nullable T lastElement (List <T > list ) {
265267 if (list .isEmpty ()) {
266268 return null ;
267269 }
@@ -275,53 +277,54 @@ private <T> T pop(List<T> list) {
275277 /**
276278 * @return can be null if the parent is not a CompositeType
277279 */
278- public GraphQLCompositeType getParentType () {
280+ public @ Nullable GraphQLCompositeType getParentType () {
279281 return lastElement (parentTypeStack );
280282 }
281283
282- private void addParentType (GraphQLCompositeType compositeType ) {
284+ private void addParentType (@ Nullable GraphQLCompositeType compositeType ) {
283285 parentTypeStack .add (compositeType );
284286 }
285287
286- public GraphQLInputType getInputType () {
288+ public @ Nullable GraphQLInputType getInputType () {
287289 return lastElement (inputTypeStack );
288290 }
289- public InputValueWithState getDefaultValue () {
291+
292+ public @ Nullable InputValueWithState getDefaultValue () {
290293 return lastElement (defaultValueStack );
291294 }
292295
293- private void addInputType (GraphQLInputType graphQLInputType ) {
296+ private void addInputType (@ Nullable GraphQLInputType graphQLInputType ) {
294297 inputTypeStack .add (graphQLInputType );
295298 }
296299
297- private void addDefaultValue (InputValueWithState defaultValue ) {
300+ private void addDefaultValue (@ Nullable InputValueWithState defaultValue ) {
298301 defaultValueStack .add (defaultValue );
299302 }
300303
301- public GraphQLFieldDefinition getFieldDef () {
304+ public @ Nullable GraphQLFieldDefinition getFieldDef () {
302305 return lastElement (fieldDefStack );
303306 }
304307
305- public List <String > getQueryPath () {
308+ public @ Nullable List <String > getQueryPath () {
306309 if (nameStack .isEmpty ()) {
307310 return null ;
308311 }
309312 return new ArrayList <>(nameStack );
310313 }
311314
312- private void addFieldDef (GraphQLFieldDefinition fieldDefinition ) {
315+ private void addFieldDef (@ Nullable GraphQLFieldDefinition fieldDefinition ) {
313316 fieldDefStack .add (fieldDefinition );
314317 }
315318
316- public GraphQLDirective getDirective () {
319+ public @ Nullable GraphQLDirective getDirective () {
317320 return directive ;
318321 }
319322
320- public GraphQLArgument getArgument () {
323+ public @ Nullable GraphQLArgument getArgument () {
321324 return argument ;
322325 }
323326
324- private GraphQLFieldDefinition getFieldDef (GraphQLSchema schema , GraphQLType parentType , Field field ) {
327+ private @ Nullable GraphQLFieldDefinition getFieldDef (GraphQLSchema schema , GraphQLType parentType , Field field ) {
325328 if (schema .getQueryType ().equals (parentType )) {
326329 if (field .getName ().equals (schema .getIntrospectionSchemaFieldDefinition ().getName ())) {
327330 return schema .getIntrospectionSchemaFieldDefinition ();
0 commit comments