11package graphql .language ;
22
3-
43import com .google .common .collect .ImmutableList ;
54import com .google .common .collect .ImmutableMap ;
65import graphql .Internal ;
3029 */
3130@ PublicApi
3231@ NullMarked
33- public class Field extends AbstractNode <Field > implements Selection <Field >, SelectionSetContainer <Field >, DirectivesContainer <Field >, NamedNode <Field > {
32+ public class Field extends AbstractNode <Field >
33+ implements Selection <Field >, SelectionSetContainer <Field >, DirectivesContainer <Field >, NamedNode <Field > {
3434
35- private final @ Nullable String name ;
35+ private final String name ;
3636 private final @ Nullable String alias ;
3737 private final ImmutableList <Argument > arguments ;
3838 private final NodeUtil .DirectivesHolder directives ;
@@ -42,17 +42,16 @@ public class Field extends AbstractNode<Field> implements Selection<Field>, Sele
4242 public static final String CHILD_DIRECTIVES = "directives" ;
4343 public static final String CHILD_SELECTION_SET = "selectionSet" ;
4444
45-
4645 @ Internal
47- protected Field (@ Nullable String name ,
48- @ Nullable String alias ,
49- List <Argument > arguments ,
50- List <Directive > directives ,
51- @ Nullable SelectionSet selectionSet ,
52- @ Nullable SourceLocation sourceLocation ,
53- List <Comment > comments ,
54- IgnoredChars ignoredChars ,
55- Map <String , String > additionalData ) {
46+ protected Field (String name ,
47+ @ Nullable String alias ,
48+ List <Argument > arguments ,
49+ List <Directive > directives ,
50+ @ Nullable SelectionSet selectionSet ,
51+ @ Nullable SourceLocation sourceLocation ,
52+ List <Comment > comments ,
53+ IgnoredChars ignoredChars ,
54+ Map <String , String > additionalData ) {
5655 super (sourceLocation , comments , ignoredChars , additionalData );
5756 this .name = name ;
5857 this .alias = alias ;
@@ -61,7 +60,6 @@ protected Field(@Nullable String name,
6160 this .selectionSet = selectionSet ;
6261 }
6362
64-
6563 /**
6664 * alternative to using a Builder for convenience
6765 *
@@ -124,24 +122,22 @@ public NodeChildrenContainer getNamedChildren() {
124122
125123 @ Override
126124 public Field withNewChildren (NodeChildrenContainer newChildren ) {
127- return transform (builder ->
128- builder .arguments (newChildren .getChildren (CHILD_ARGUMENTS ))
129- .directives (newChildren .getChildren (CHILD_DIRECTIVES ))
130- .selectionSet (newChildren .getChildOrNull (CHILD_SELECTION_SET ))
131- );
125+ return transform (builder -> builder .arguments (newChildren .getChildren (CHILD_ARGUMENTS ))
126+ .directives (newChildren .getChildren (CHILD_DIRECTIVES ))
127+ .selectionSet (newChildren .getChildOrNull (CHILD_SELECTION_SET )));
132128 }
133129
134130 @ Override
135131 public String getName () {
136- return assertNotNull ( name , () -> "name cannot be null" ) ;
132+ return name ;
137133 }
138134
139135 public @ Nullable String getAlias () {
140136 return alias ;
141137 }
142138
143139 public String getResultKey () {
144- return alias != null ? alias : assertNotNull ( name , () -> "name cannot be null" ) ;
140+ return alias != null ? alias : name ;
145141 }
146142
147143 public List <Argument > getArguments () {
@@ -173,7 +169,6 @@ public boolean hasDirective(String directiveName) {
173169 return selectionSet ;
174170 }
175171
176-
177172 @ Override
178173 public boolean isEqualTo (@ Nullable Node o ) {
179174 if (this == o ) {
@@ -198,8 +193,7 @@ public Field deepCopy() {
198193 getSourceLocation (),
199194 getComments (),
200195 getIgnoredChars (),
201- getAdditionalData ()
202- );
196+ getAdditionalData ());
203197 }
204198
205199 @ Override
@@ -262,7 +256,6 @@ private Builder(Field existing) {
262256 this .additionalData = copyOf (existing .getAdditionalData ());
263257 }
264258
265-
266259 public Builder sourceLocation (@ Nullable SourceLocation sourceLocation ) {
267260 this .sourceLocation = sourceLocation ;
268261 return this ;
@@ -319,9 +312,9 @@ public Builder additionalData(String key, String value) {
319312 return this ;
320313 }
321314
322-
323315 public Field build () {
324- return new Field (name , alias , arguments , directives , selectionSet , sourceLocation , comments , ignoredChars , additionalData );
316+ return new Field (assertNotNull (name ), alias , arguments , directives , selectionSet , sourceLocation , comments ,
317+ ignoredChars , additionalData );
325318 }
326319 }
327320}
0 commit comments