2828import java .util .Map ;
2929import java .util .Set ;
3030import java .util .function .Consumer ;
31- import java .util .stream .Collectors ;
3231
3332import static graphql .Assert .assertNotNull ;
3433import static graphql .Assert .assertTrue ;
3534import static graphql .schema .GraphQLTypeUtil .simplePrint ;
3635import static graphql .schema .GraphQLTypeUtil .unwrapAll ;
36+ import static java .util .stream .Collectors .joining ;
37+ import static java .util .stream .Collectors .toList ;
38+ import static java .util .stream .Collectors .toSet ;
3739
3840/**
3941 * Intentionally Mutable
@@ -193,7 +195,7 @@ public boolean hasChildren() {
193195
194196 public GraphQLOutputType getType (GraphQLSchema schema ) {
195197 List <GraphQLFieldDefinition > fieldDefinitions = getFieldDefinitions (schema );
196- Set <String > fieldTypes = fieldDefinitions .stream ().map (fd -> simplePrint (fd .getType ())).collect (Collectors . toSet ());
198+ Set <String > fieldTypes = fieldDefinitions .stream ().map (fd -> simplePrint (fd .getType ())).collect (toSet ());
197199 Assert .assertTrue (fieldTypes .size () == 1 , () -> "More than one type ... use getTypes" );
198200 return fieldDefinitions .get (0 ).getType ();
199201 }
@@ -355,6 +357,29 @@ public List<ExecutableNormalizedField> getChildrenWithSameResultKey(String resul
355357 return FpKit .filterList (children , child -> child .getResultKey ().equals (resultKey ));
356358 }
357359
360+ public List <ExecutableNormalizedField > getChildren (int includingRelativeLevel ) {
361+ List <ExecutableNormalizedField > result = new ArrayList <>();
362+ assertTrue (includingRelativeLevel >= 1 , () -> "relative level must be >= 1" );
363+
364+ this .getChildren ().forEach (child -> {
365+ traverseImpl (child , result ::add , 1 , includingRelativeLevel );
366+ });
367+ return result ;
368+ }
369+
370+ /**
371+ * This returns the child fields that can be used if the object is of the specified object type
372+ *
373+ * @param objectTypeName the object type
374+ *
375+ * @return a list of child fields that would apply to that object type
376+ */
377+ public List <ExecutableNormalizedField > getChildren (String objectTypeName ) {
378+ return children .stream ()
379+ .filter (cld -> cld .objectTypeNames .contains (objectTypeName ))
380+ .collect (toList ());
381+ }
382+
358383 public int getLevel () {
359384 return level ;
360385 }
@@ -374,19 +399,10 @@ public String toString() {
374399 objectTypeNamesToString () + "." + fieldName +
375400 ", alias=" + alias +
376401 ", level=" + level +
377- ", children=" + children .stream ().map (ExecutableNormalizedField ::toString ).collect (Collectors . joining ("\n " )) +
402+ ", children=" + children .stream ().map (ExecutableNormalizedField ::toString ).collect (joining ("\n " )) +
378403 '}' ;
379404 }
380405
381- public List <ExecutableNormalizedField > getChildren (int includingRelativeLevel ) {
382- List <ExecutableNormalizedField > result = new ArrayList <>();
383- assertTrue (includingRelativeLevel >= 1 , () -> "relative level must be >= 1" );
384-
385- this .getChildren ().forEach (child -> {
386- traverseImpl (child , result ::add , 1 , includingRelativeLevel );
387- });
388- return result ;
389- }
390406
391407 public void traverseSubTree (Consumer <ExecutableNormalizedField > consumer ) {
392408 this .getChildren ().forEach (child -> {
0 commit comments