@@ -70,16 +70,51 @@ public Map<String, Object> getVariables() {
7070 }
7171 }
7272
73- public static CompilerResult compileToDocument (@ NotNull GraphQLSchema schema ,
73+ public static CompilerResult compileToDocument (GraphQLSchema graphQLSchema ,
74+ GraphQLObjectType rootType ,
75+ List <NormalizedField > rootFields ,
76+ @ Nullable String operationName ,
77+ OperationDefinition .Operation operationKind ) {
78+
79+ return compileToDocumentImpl (graphQLSchema , rootType , rootFields , operationName , operationKind );
80+ }
81+
82+ public static CompilerResult compileToDocument (GraphQLSchema graphQLSchema ,
83+ GraphQLObjectType rootType ,
84+ NormalizedField singleRootField ,
85+ @ Nullable String operationName ,
86+ OperationDefinition .Operation operationKind ) {
87+ return compileToDocumentImpl (graphQLSchema , rootType , ImmutableList .of (singleRootField ), operationName , operationKind );
88+
89+
90+ }
91+
92+
93+ public static CompilerResult compileToDocument (GraphQLSchema schema ,
7494 NormalizedOperation normalizedOperation ) {
7595 GraphQLObjectType operationType = getOperationType (schema , normalizedOperation .getOperation ());
7696
77- List <Selection <?>> selections = subSelectionsForNormalizedField (schema , operationType .getName (), normalizedOperation .getRootFields ());
97+ return compileToDocumentImpl (
98+ schema ,
99+ operationType ,
100+ normalizedOperation .getRootFields (),
101+ normalizedOperation .getOperationName (),
102+ normalizedOperation .getOperation ()
103+ );
104+ }
105+
106+ private static CompilerResult compileToDocumentImpl (GraphQLSchema schema ,
107+ GraphQLObjectType rootType ,
108+ List <NormalizedField > rootFields ,
109+ @ Nullable String operationName ,
110+ OperationDefinition .Operation operationKind ) {
111+
112+ List <Selection <?>> selections = subSelectionsForNormalizedFields (schema , rootType .getName (), rootFields );
78113 SelectionSet selectionSet = new SelectionSet (selections );
79114
80115 OperationDefinition .Builder definitionBuilder = OperationDefinition .newOperationDefinition ()
81- .name (normalizedOperation . getOperationName () )
82- .operation (normalizedOperation . getOperation () )
116+ .name (operationName )
117+ .operation (operationKind )
83118 .selectionSet (selectionSet );
84119
85120// definitionBuilder.variableDefinitions(variableAccumulator.getVariableDefinitions());
@@ -92,9 +127,10 @@ public static CompilerResult compileToDocument(@NotNull GraphQLSchema schema,
92127 );
93128 }
94129
95- private static List <Selection <?>> subSelectionsForNormalizedField (GraphQLSchema schema ,
96- @ NotNull String parentOutputType ,
97- List <NormalizedField > normalizedFields
130+
131+ private static List <Selection <?>> subSelectionsForNormalizedFields (GraphQLSchema schema ,
132+ @ NotNull String parentOutputType ,
133+ List <NormalizedField > normalizedFields
98134 ) {
99135 ImmutableList .Builder <Selection <?>> selections = ImmutableList .builder ();
100136
@@ -155,7 +191,7 @@ private static Field selectionForNormalizedField(GraphQLSchema schema,
155191 GraphQLFieldDefinition fieldDef = getFieldDefinition (schema , objectTypeName , normalizedField );
156192 GraphQLUnmodifiedType fieldOutputType = unwrapAll (fieldDef .getType ());
157193
158- subSelections = subSelectionsForNormalizedField (
194+ subSelections = subSelectionsForNormalizedFields (
159195 schema ,
160196 fieldOutputType .getName (),
161197 normalizedField .getChildren ()
@@ -195,7 +231,6 @@ private static GraphQLFieldDefinition getFieldDefinition(GraphQLSchema schema,
195231 }
196232
197233
198- @ Nullable
199234 private static GraphQLObjectType getOperationType (@ NotNull GraphQLSchema schema ,
200235 @ NotNull OperationDefinition .Operation operationKind ) {
201236 switch (operationKind ) {
0 commit comments