private boolean isDataLoaderCompatibleExecution(ExecutionContext executionContext) { // // currently we only support Query operations and ONLY with AsyncExecutionStrategy as the query ES // This may change in the future but this is the fix for now // if (executionContext.getOperationDefinition().getOperation() == OperationDefinition.Operation.QUERY) { ExecutionStrategy queryStrategy = executionContext.getQueryStrategy(); if (queryStrategy instanceof AsyncExecutionStrategy) { return true; } } return false; }
@Internal ExecutionContextBuilder(ExecutionContext other) { instrumentation = other.getInstrumentation(); executionId = other.getExecutionId(); instrumentationState = other.getInstrumentationState(); graphQLSchema = other.getGraphQLSchema(); queryStrategy = other.getQueryStrategy(); mutationStrategy = other.getMutationStrategy(); subscriptionStrategy = other.getSubscriptionStrategy(); context = other.getContext(); root = other.getRoot(); document = other.getDocument(); operationDefinition = other.getOperationDefinition(); variables = new HashMap<>(other.getVariables()); fragmentsByName = new HashMap<>(other.getFragmentsByName()); dataLoaderRegistry = other.getDataLoaderRegistry(); errors = new ArrayList<>(other.getErrors()); }
static List<GraphQLError> validateFieldsAndArguments(FieldValidation fieldValidation, ExecutionContext executionContext) { Map<ExecutionPath, List<FieldAndArguments>> fieldArgumentsMap = new LinkedHashMap<>(); QueryTraversal queryTraversal = QueryTraversal.newQueryTraversal() .schema(executionContext.getGraphQLSchema()) .document(executionContext.getDocument()) .operationName(executionContext.getOperationDefinition().getName()) .variables(executionContext.getVariables()) .build(); queryTraversal.visitPreOrder(new QueryVisitorStub() { @Override public void visitField(QueryVisitorFieldEnvironment env) { Field field = env.getField(); if (field.getArguments() != null && !field.getArguments().isEmpty()) { // // only fields that have arguments make any sense to placed in play // since only they have variable input FieldAndArguments fieldArguments = new FieldAndArgumentsImpl(env); ExecutionPath path = fieldArguments.getPath(); List<FieldAndArguments> list = fieldArgumentsMap.getOrDefault(path, new ArrayList<>()); list.add(fieldArguments); fieldArgumentsMap.put(path, list); } } }); FieldValidationEnvironment environment = new FieldValidationEnvironmentImpl(executionContext, fieldArgumentsMap); // // this will allow a consumer to plugin their own validation of fields and arguments return fieldValidation.validateFields(environment); }
public static Builder newDataFetchingEnvironment(ExecutionContext executionContext) { return new Builder() .context(executionContext.getContext()) .root(executionContext.getRoot()) .graphQLSchema(executionContext.getGraphQLSchema()) .fragmentsByName(executionContext.getFragmentsByName()) .dataLoaderRegistry(executionContext.getDataLoaderRegistry()) .document(executionContext.getDocument()) .operationDefinition(executionContext.getOperationDefinition()) .variables(executionContext.getVariables()) .executionId(executionContext.getExecutionId()); }
); executionContext = instrumentation.instrumentExecutionContext(executionContext, parameters); return executeOperation(executionContext, parameters, executionInput.getRoot(), executionContext.getOperationDefinition());
public OperationDefinition getOperationDefinition() { return delegate.getOperationDefinition(); }
protected GraphQLExecutionContext wrapIfAny(ExecutionContext executionContext) { if (executionContext instanceof GraphQLExecutionContext) { return (GraphQLExecutionContext) executionContext; } else { int currentDepth = executionContext.getOperationDefinition().getOperation() == OperationDefinition.Operation.MUTATION ? 1 : 0; return new GraphQLExecutionContext(executionContext, currentDepth); } }
private boolean isDataLoaderCompatibleExecution(ExecutionContext executionContext) { // // currently we only support Query operations and ONLY with AsyncExecutionStrategy as the query ES // This may change in the future but this is the fix for now // if (executionContext.getOperationDefinition().getOperation() == OperationDefinition.Operation.QUERY) { ExecutionStrategy queryStrategy = executionContext.getQueryStrategy(); if (queryStrategy instanceof AsyncExecutionStrategy) { return true; } } return false; }
@Override public InstrumentationContext<ExecutionResult> beginExecuteOperation(InstrumentationExecuteOperationParameters parameters) { ResolvedField root = new ComplexityAnalyzer(complexityFunction, maximumComplexity).collectFields(parameters.getExecutionContext()); if (log.isDebugEnabled()) { log.debug("Operation {} has total complexity of {}", AstPrinter.printAst(parameters.getExecutionContext().getOperationDefinition().getSelectionSet().getSelections().get(0)), root.getComplexityScore()); } log.info("Total operation complexity: {}", root.getComplexityScore()); return super.beginExecuteOperation(parameters); } }
Map<String, List<Map<String, Object>>> operationDirectives = parseDirectives(env.getExecutionContext().getOperationDefinition().getDirectives(), env); if (OperationDefinition.Operation.MUTATION.equals(env.getExecutionContext().getOperationDefinition().getOperation())) { directives.put(Introspection.DirectiveLocation.MUTATION, operationDirectives); directives.put(Introspection.DirectiveLocation.QUERY, Collections.emptyMap());
public ExecutionResult execute(GraphQLSchema graphQLSchema, Object root, Document document, String operationName, Map<String, Object> args) { ExecutionContextBuilder executionContextBuilder = new ExecutionContextBuilder(new ValuesResolver()); ExecutionContext executionContext = executionContextBuilder.build(graphQLSchema, strategy, root, document, operationName, args); return executeOperation(executionContext, root, executionContext.getOperationDefinition()); }
private ExecutionResult executeOperation( ExecutionContext executionContext, Object root, OperationDefinition operationDefinition) { GraphQLObjectType operationRootType = getOperationRootType(executionContext.getGraphQLSchema(), executionContext.getOperationDefinition()); Map<String, List<Field>> fields = new LinkedHashMap<String, List<Field>>(); fieldCollector.collectFields(executionContext, operationRootType, operationDefinition.getSelectionSet(), new ArrayList<String>(), fields); if (operationDefinition.getOperation() == OperationDefinition.Operation.MUTATION) { return new GraphQLDefaultRxExecutionStrategy(graphQLSchemaHolder, maxQueryDepth, maxQueryComplexity) .execute(executionContext, operationRootType, root, fields); } else { return strategy.execute(executionContext, operationRootType, root, fields); } } }
ResolvedField collectFields(ExecutionContext context) { FieldCollectorParameters parameters = FieldCollectorParameters.newParameters() .schema(context.getGraphQLSchema()) .objectType(context.getGraphQLSchema().getQueryType()) .fragments(context.getFragmentsByName()) .variables(context.getVariables()) .build(); List<Field> fields = context.getOperationDefinition().getSelectionSet().getSelections().stream() .map(selection -> (Field) selection) .collect(Collectors.toList()); Field field = fields.get(0); GraphQLFieldDefinition fieldDefinition; if (GraphQLUtils.isIntrospectionField(field)) { fieldDefinition = Introspection.SchemaMetaFieldDef; } else { fieldDefinition = Objects.requireNonNull( getRootType(context.getGraphQLSchema(), context.getOperationDefinition()) .getFieldDefinition(field.getName())); } Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDefinition.getArguments(), field.getArguments(), context.getVariables()); return collectFields(parameters, fields.stream().map(f -> new ResolvedField(f, fieldDefinition, argumentValues)).collect(Collectors.toList())); }
Field field = (Field) executionContext.getOperationDefinition().getSelectionSet().getSelections().get(0); Argument argument = field.getArguments().get(0);
@Internal ExecutionContextBuilder(ExecutionContext other) { instrumentation = other.getInstrumentation(); executionId = other.getExecutionId(); instrumentationState = other.getInstrumentationState(); graphQLSchema = other.getGraphQLSchema(); queryStrategy = other.getQueryStrategy(); mutationStrategy = other.getMutationStrategy(); subscriptionStrategy = other.getSubscriptionStrategy(); context = other.getContext(); root = other.getRoot(); document = other.getDocument(); operationDefinition = other.getOperationDefinition(); variables = new HashMap<>(other.getVariables()); fragmentsByName = new HashMap<>(other.getFragmentsByName()); dataLoaderRegistry = other.getDataLoaderRegistry(); errors = new ArrayList<>(other.getErrors()); }
Field field = (Field) executionContext.getOperationDefinition().getSelectionSet().getSelections().get(0); Argument argument = field.getArguments().get(0);
public ReactiveContext(ExecutionContext context, Object key) { super( context.getInstrumentation(), context.getExecutionId(), context.getGraphQLSchema(), context.getQueryStrategy(), context.getMutationStrategy(), context.getSubscriptionStrategy(), context.getFragmentsByName(), context.getOperationDefinition(), context.getVariables(), context.getRoot() ); this.key = key; this.parent = context; }
static List<GraphQLError> validateFieldsAndArguments(FieldValidation fieldValidation, ExecutionContext executionContext) { Map<ExecutionPath, List<FieldAndArguments>> fieldArgumentsMap = new LinkedHashMap<>(); QueryTraversal queryTraversal = QueryTraversal.newQueryTraversal() .schema(executionContext.getGraphQLSchema()) .document(executionContext.getDocument()) .operationName(executionContext.getOperationDefinition().getName()) .variables(executionContext.getVariables()) .build(); queryTraversal.visitPreOrder(new QueryVisitorStub() { @Override public void visitField(QueryVisitorFieldEnvironment env) { Field field = env.getField(); if (field.getArguments() != null && !field.getArguments().isEmpty()) { // // only fields that have arguments make any sense to placed in play // since only they have variable input FieldAndArguments fieldArguments = new FieldAndArgumentsImpl(env); ExecutionPath path = fieldArguments.getPath(); List<FieldAndArguments> list = fieldArgumentsMap.getOrDefault(path, new ArrayList<>()); list.add(fieldArguments); fieldArgumentsMap.put(path, list); } } }); FieldValidationEnvironment environment = new FieldValidationEnvironmentImpl(executionContext, fieldArgumentsMap); // // this will allow a consumer to plugin their own validation of fields and arguments return fieldValidation.validateFields(environment); }
public static Builder newDataFetchingEnvironment(ExecutionContext executionContext) { return new Builder() .context(executionContext.getContext()) .root(executionContext.getRoot()) .graphQLSchema(executionContext.getGraphQLSchema()) .fragmentsByName(executionContext.getFragmentsByName()) .dataLoaderRegistry(executionContext.getDataLoaderRegistry()) .document(executionContext.getDocument()) .operationDefinition(executionContext.getOperationDefinition()) .variables(executionContext.getVariables()) .executionId(executionContext.getExecutionId()); }
); executionContext = instrumentation.instrumentExecutionContext(executionContext, parameters); return executeOperation(executionContext, parameters, executionInput.getRoot(), executionContext.getOperationDefinition());