3131
3232import static graphql .Assert .assertNotNull ;
3333import static graphql .collect .ImmutableKit .map ;
34+ import static graphql .execution .nextgen .Common .getOperationRootType ;
3435import static graphql .language .Argument .newArgument ;
3536import static graphql .language .Field .newField ;
3637import static graphql .language .InlineFragment .newInlineFragment ;
@@ -66,8 +67,7 @@ public static CompilerResult compileToDocument(@NotNull GraphQLSchema schema,
6667 @ Nullable String operationName ,
6768 @ NotNull List <ExecutableNormalizedField > topLevelFields ,
6869 @ Nullable VariablePredicate variablePredicate ) {
69- GraphQLObjectType operationType = assertNotNull (getOperationType (schema , operationKind ),
70- () -> "Schema does not support " + operationKind .name ().toLowerCase () + " operations" );
70+ GraphQLObjectType operationType = getOperationRootType (schema , operationKind );
7171
7272 VariableAccumulator variableAccumulator = new VariableAccumulator (variablePredicate );
7373 List <Selection <?>> selections = subselectionsForNormalizedField (schema , operationType .getName (), topLevelFields , variableAccumulator );
@@ -89,7 +89,7 @@ public static CompilerResult compileToDocument(@NotNull GraphQLSchema schema,
8989 }
9090
9191 private static List <Selection <?>> subselectionsForNormalizedField (GraphQLSchema schema ,
92- @ Nullable String parentOutputType ,
92+ @ NotNull String parentOutputType ,
9393 List <ExecutableNormalizedField > executableNormalizedFields ,
9494 VariableAccumulator variableAccumulator ) {
9595 ImmutableList .Builder <Selection <?>> selections = ImmutableList .builder ();
@@ -240,19 +240,4 @@ private static GraphQLFieldDefinition getFieldDefinition(GraphQLSchema schema,
240240 ExecutableNormalizedField nf ) {
241241 return schema .getFieldDefinition (coordinates (parentType , nf .getName ()));
242242 }
243-
244- @ Nullable
245- private static GraphQLObjectType getOperationType (@ NotNull GraphQLSchema schema ,
246- @ NotNull OperationDefinition .Operation operationKind ) {
247- switch (operationKind ) {
248- case QUERY :
249- return schema .getQueryType ();
250- case MUTATION :
251- return schema .getMutationType ();
252- case SUBSCRIPTION :
253- return schema .getSubscriptionType ();
254- }
255-
256- return Assert .assertShouldNeverHappen ("Unknown operation kind " + operationKind );
257- }
258243}
0 commit comments