diff --git a/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/engine/GraphQLEngine.java b/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/engine/GraphQLEngine.java index b1b5e7d34..c9f8a703b 100644 --- a/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/engine/GraphQLEngine.java +++ b/nop-graphql/nop-graphql-core/src/main/java/io/nop/graphql/core/engine/GraphQLEngine.java @@ -326,8 +326,7 @@ public void initGraphQLContext(IGraphQLExecutionContext context, ParsedGraphQLRe } validateDocument(doc); - Map vars = request.getVariables(); - GraphQLOperation op = (GraphQLOperation) doc.getDefinitions().get(0); + GraphQLOperation op = doc.getOperation(); if (op.getSelectionSet() == null || op.getSelectionSet().isEmpty()) throw new NopException(ERR_GRAPHQL_QUERY_NO_OPERATION); @@ -337,6 +336,8 @@ public void initGraphQLContext(IGraphQLExecutionContext context, ParsedGraphQLRe context.setOperation(op); context.setExecutionId(request.getOperationId()); + + Map vars = request.getVariables(); FieldSelectionBean selectionBean = buildSelectionBean(op.getName(), op.getSelectionSet(), vars); context.setFieldSelection(selectionBean); } @@ -560,4 +561,4 @@ public CompletionStage fetchResult(Object result, IGraphQLExecutionConte IGraphQLExecutor executor = new GraphQLExecutor(operationInvoker, graphQLHook, flowControlRunner, this); return executor.fetchResult(result, context); } -} \ No newline at end of file +}