use of graphql.language.FragmentDefinition in project graphql-java by graphql-java.
the class Execution method execute.
public CompletableFuture<ExecutionResult> execute(Document document, GraphQLSchema graphQLSchema, ExecutionId executionId, ExecutionInput executionInput, InstrumentationState instrumentationState) {
NodeUtil.GetOperationResult getOperationResult = NodeUtil.getOperation(document, executionInput.getOperationName());
Map<String, FragmentDefinition> fragmentsByName = getOperationResult.fragmentsByName;
OperationDefinition operationDefinition = getOperationResult.operationDefinition;
ValuesResolver valuesResolver = new ValuesResolver();
Map<String, Object> inputVariables = executionInput.getVariables();
List<VariableDefinition> variableDefinitions = operationDefinition.getVariableDefinitions();
Map<String, Object> coercedVariables;
try {
coercedVariables = valuesResolver.coerceArgumentValues(graphQLSchema, variableDefinitions, inputVariables);
} catch (RuntimeException rte) {
if (rte instanceof GraphQLError) {
return completedFuture(new ExecutionResultImpl((GraphQLError) rte));
}
throw rte;
}
ExecutionContext executionContext = newExecutionContextBuilder().instrumentation(instrumentation).instrumentationState(instrumentationState).executionId(executionId).graphQLSchema(graphQLSchema).queryStrategy(queryStrategy).mutationStrategy(mutationStrategy).subscriptionStrategy(subscriptionStrategy).context(executionInput.getContext()).root(executionInput.getRoot()).fragmentsByName(fragmentsByName).variables(coercedVariables).document(document).operationDefinition(operationDefinition).build();
InstrumentationExecutionParameters parameters = new InstrumentationExecutionParameters(executionInput, graphQLSchema, instrumentationState);
executionContext = instrumentation.instrumentExecutionContext(executionContext, parameters);
return executeOperation(executionContext, parameters, executionInput.getRoot(), executionContext.getOperationDefinition());
}
use of graphql.language.FragmentDefinition in project graphql-java by graphql-java.
the class FieldCollector method collectFragmentSpread.
private void collectFragmentSpread(FieldCollectorParameters parameters, List<String> visitedFragments, Map<String, List<Field>> fields, FragmentSpread fragmentSpread) {
if (visitedFragments.contains(fragmentSpread.getName())) {
return;
}
if (!conditionalNodes.shouldInclude(parameters.getVariables(), fragmentSpread.getDirectives())) {
return;
}
visitedFragments.add(fragmentSpread.getName());
FragmentDefinition fragmentDefinition = parameters.getFragmentsByName().get(fragmentSpread.getName());
if (!conditionalNodes.shouldInclude(parameters.getVariables(), fragmentDefinition.getDirectives())) {
return;
}
if (!doesFragmentConditionMatch(parameters, fragmentDefinition)) {
return;
}
collectFields(parameters, fragmentDefinition.getSelectionSet(), visitedFragments, fields);
}
use of graphql.language.FragmentDefinition in project graphql-java by graphql-java.
the class ValidationContext method buildFragmentMap.
private void buildFragmentMap() {
for (Definition definition : document.getDefinitions()) {
if (!(definition instanceof FragmentDefinition))
continue;
FragmentDefinition fragmentDefinition = (FragmentDefinition) definition;
fragmentDefinitionMap.put(fragmentDefinition.getName(), fragmentDefinition);
}
}
use of graphql.language.FragmentDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitDirective.
@Override
public Void visitDirective(GraphqlParser.DirectiveContext ctx) {
Directive directive = new Directive(ctx.name().getText());
newNode(directive, ctx);
for (ContextEntry contextEntry : contextStack) {
if (contextEntry.contextProperty == ContextProperty.Field) {
((Field) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.FragmentDefinition) {
((FragmentDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.FragmentSpread) {
((FragmentSpread) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.InlineFragment) {
((InlineFragment) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.OperationDefinition) {
((OperationDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.EnumValueDefinition) {
((EnumValueDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.FieldDefinition) {
((FieldDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.InputValueDefinition) {
((InputValueDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.InterfaceTypeDefinition) {
((InterfaceTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.EnumTypeDefinition) {
((EnumTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.ObjectTypeDefinition) {
((ObjectTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.ScalarTypeDefinition) {
((ScalarTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.UnionTypeDefinition) {
((UnionTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.InputObjectTypeDefinition) {
((InputObjectTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.SchemaDefinition) {
((SchemaDefinition) contextEntry.value).getDirectives().add(directive);
break;
}
}
addContextProperty(ContextProperty.Directive, directive);
super.visitDirective(ctx);
popContext();
return null;
}
use of graphql.language.FragmentDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitFragmentDefinition.
@Override
public Void visitFragmentDefinition(GraphqlParser.FragmentDefinitionContext ctx) {
FragmentDefinition fragmentDefinition = new FragmentDefinition();
newNode(fragmentDefinition, ctx);
fragmentDefinition.setName(ctx.fragmentName().getText());
fragmentDefinition.setTypeCondition(new TypeName(ctx.typeCondition().typeName().getText()));
addContextProperty(ContextProperty.FragmentDefinition, fragmentDefinition);
result.getDefinitions().add(fragmentDefinition);
super.visitFragmentDefinition(ctx);
popContext();
return null;
}
Aggregations