11package graphql .execution .nextgen .result ;
22
3- import graphql .Assert ;
43import graphql .PublicApi ;
54import graphql .util .NodeAdapter ;
65import graphql .util .NodeLocation ;
98import java .util .List ;
109import java .util .Map ;
1110
11+ import static graphql .Assert .assertNotNull ;
12+ import static graphql .Assert .assertTrue ;
13+
1214@ PublicApi
1315public class ResultNodeAdapter implements NodeAdapter <ExecutionResultNode > {
1416
@@ -19,22 +21,26 @@ private ResultNodeAdapter() {
1921 }
2022
2123 @ Override
22- public Map <String , List <ExecutionResultNode >> getNamedChildren (ExecutionResultNode node ) {
24+ public Map <String , List <ExecutionResultNode >> getNamedChildren (ExecutionResultNode parentNode ) {
2325 Map <String , List <ExecutionResultNode >> result = new LinkedHashMap <>();
24- result .put (null , node .getChildren ());
26+ result .put (null , parentNode .getChildren ());
2527 return result ;
2628 }
2729
2830 @ Override
29- public ExecutionResultNode withNewChildren (ExecutionResultNode node , Map <String , List <ExecutionResultNode >> newChildren ) {
30- Assert . assertTrue (newChildren .size () == 1 );
31+ public ExecutionResultNode withNewChildren (ExecutionResultNode parentNode , Map <String , List <ExecutionResultNode >> newChildren ) {
32+ assertTrue (newChildren .size () == 1 );
3133 List <ExecutionResultNode > childrenList = newChildren .get (null );
32- Assert . assertNotNull (childrenList );
33- return node .withNewChildren (childrenList );
34+ assertNotNull (childrenList );
35+ return parentNode .withNewChildren (childrenList );
3436 }
3537
3638 @ Override
37- public ExecutionResultNode removeChild (ExecutionResultNode node , NodeLocation location ) {
38- throw new UnsupportedOperationException ();
39+ public ExecutionResultNode removeChild (ExecutionResultNode parentNode , NodeLocation location ) {
40+ int index = location .getIndex ();
41+ List <ExecutionResultNode > childrenList = parentNode .getChildren ();
42+ assertTrue (index >= 0 && index < childrenList .size (), "The remove index MUST be within the range of the children" );
43+ childrenList .remove (index );
44+ return parentNode .withNewChildren (childrenList );
3945 }
4046}
0 commit comments