Package graphql.normalized
Class ExecutableNormalizedOperationToAstCompiler
- java.lang.Object
-
- graphql.normalized.ExecutableNormalizedOperationToAstCompiler
-
@PublicApi public class ExecutableNormalizedOperationToAstCompiler extends java.lang.Object
This class can take a list ofExecutableNormalizedField
s and compiling out a normalised operationDocument
that would represent how those fields maybe executed.This is essentially the reverse of
ExecutableNormalizedOperationFactory
which takes operation text and makesExecutableNormalizedField
s from it, this takesExecutableNormalizedField
s and makes operation text from it.You could for example send that operation text onto to some other graphql server if it has the same schema as the one provided.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExecutableNormalizedOperationToAstCompiler.CompilerResult
The result is aDocument
and a map of variables that would go with that document.
-
Constructor Summary
Constructors Constructor Description ExecutableNormalizedOperationToAstCompiler()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static Value<?>
argValue(ExecutableNormalizedField executableNormalizedField, java.lang.String argName, @Nullable java.lang.Object value, VariableAccumulator variableAccumulator)
private static @NotNull Value<?>
argValue(ExecutableNormalizedField executableNormalizedField, java.lang.String argName, NormalizedInputValue normalizedInputValue, VariableAccumulator variableAccumulator)
static ExecutableNormalizedOperationToAstCompiler.CompilerResult
compileToDocument(@NotNull GraphQLSchema schema, OperationDefinition.Operation operationKind, @Nullable java.lang.String operationName, @NotNull java.util.List<ExecutableNormalizedField> topLevelFields, @NotNull java.util.Map<ExecutableNormalizedField,QueryDirectives> normalizedFieldToQueryDirectives, @Nullable VariablePredicate variablePredicate)
This will compile an operation textDocument
with possibly variables from the givenExecutableNormalizedField
s TheVariablePredicate
is used called to decide if the given argument values should be made into a variable OR inlined into the operation text as a graphql literal.static ExecutableNormalizedOperationToAstCompiler.CompilerResult
compileToDocument(@NotNull GraphQLSchema schema, OperationDefinition.Operation operationKind, @Nullable java.lang.String operationName, @NotNull java.util.List<ExecutableNormalizedField> topLevelFields, @Nullable VariablePredicate variablePredicate)
This will compile an operation textDocument
with possibly variables from the givenExecutableNormalizedField
s TheVariablePredicate
is used called to decide if the given argument values should be made into a variable OR inlined into the operation text as a graphql literal.private static java.util.List<Argument>
createArguments(ExecutableNormalizedField executableNormalizedField, VariableAccumulator variableAccumulator)
private static @NotNull GraphQLFieldDefinition
getFieldDefinition(GraphQLSchema schema, java.lang.String parentType, ExecutableNormalizedField nf)
private static @Nullable GraphQLObjectType
getOperationType(@NotNull GraphQLSchema schema, OperationDefinition.Operation operationKind)
private static java.util.Map<java.lang.String,Field>
selectionForNormalizedField(GraphQLSchema schema, ExecutableNormalizedField executableNormalizedField, @NotNull java.util.Map<ExecutableNormalizedField,QueryDirectives> normalizedFieldToQueryDirectives, VariableAccumulator variableAccumulator)
private static Field
selectionForNormalizedField(GraphQLSchema schema, java.lang.String objectTypeName, ExecutableNormalizedField executableNormalizedField, @NotNull java.util.Map<ExecutableNormalizedField,QueryDirectives> normalizedFieldToQueryDirectives, VariableAccumulator variableAccumulator)
private static SelectionSet
selectionSet(java.util.List<Field> fields)
private static @Nullable SelectionSet
selectionSetOrNullIfEmpty(java.util.List<Selection<?>> selections)
private static java.util.List<Selection<?>>
subselectionsForNormalizedField(GraphQLSchema schema, @NotNull java.lang.String parentOutputType, java.util.List<ExecutableNormalizedField> executableNormalizedFields, @NotNull java.util.Map<ExecutableNormalizedField,QueryDirectives> normalizedFieldToQueryDirectives, VariableAccumulator variableAccumulator)
-
-
-
Method Detail
-
compileToDocument
public static ExecutableNormalizedOperationToAstCompiler.CompilerResult compileToDocument(@NotNull @NotNull GraphQLSchema schema, @NotNull OperationDefinition.Operation operationKind, @Nullable @Nullable java.lang.String operationName, @NotNull @NotNull java.util.List<ExecutableNormalizedField> topLevelFields, @Nullable @Nullable VariablePredicate variablePredicate)
This will compile an operation textDocument
with possibly variables from the givenExecutableNormalizedField
s TheVariablePredicate
is used called to decide if the given argument values should be made into a variable OR inlined into the operation text as a graphql literal.- Parameters:
schema
- the graphql schema to useoperationKind
- the kind of operationoperationName
- the name of the operation to usetopLevelFields
- the top levelExecutableNormalizedField
s to start fromvariablePredicate
- the variable predicate that decides if arguments turn into variables or not during compilation- Returns:
- a
ExecutableNormalizedOperationToAstCompiler.CompilerResult
object
-
compileToDocument
public static ExecutableNormalizedOperationToAstCompiler.CompilerResult compileToDocument(@NotNull @NotNull GraphQLSchema schema, @NotNull OperationDefinition.Operation operationKind, @Nullable @Nullable java.lang.String operationName, @NotNull @NotNull java.util.List<ExecutableNormalizedField> topLevelFields, @NotNull @NotNull java.util.Map<ExecutableNormalizedField,QueryDirectives> normalizedFieldToQueryDirectives, @Nullable @Nullable VariablePredicate variablePredicate)
This will compile an operation textDocument
with possibly variables from the givenExecutableNormalizedField
s TheVariablePredicate
is used called to decide if the given argument values should be made into a variable OR inlined into the operation text as a graphql literal.- Parameters:
schema
- the graphql schema to useoperationKind
- the kind of operationoperationName
- the name of the operation to usetopLevelFields
- the top levelExecutableNormalizedField
s to start fromnormalizedFieldToQueryDirectives
- the map of normalized field to query directivesvariablePredicate
- the variable predicate that decides if arguments turn into variables or not during compilation- Returns:
- a
ExecutableNormalizedOperationToAstCompiler.CompilerResult
object
-
subselectionsForNormalizedField
private static java.util.List<Selection<?>> subselectionsForNormalizedField(GraphQLSchema schema, @NotNull @NotNull java.lang.String parentOutputType, java.util.List<ExecutableNormalizedField> executableNormalizedFields, @NotNull @NotNull java.util.Map<ExecutableNormalizedField,QueryDirectives> normalizedFieldToQueryDirectives, VariableAccumulator variableAccumulator)
-
selectionForNormalizedField
private static java.util.Map<java.lang.String,Field> selectionForNormalizedField(GraphQLSchema schema, ExecutableNormalizedField executableNormalizedField, @NotNull @NotNull java.util.Map<ExecutableNormalizedField,QueryDirectives> normalizedFieldToQueryDirectives, VariableAccumulator variableAccumulator)
- Returns:
- Map of object type names to list of fields
-
selectionForNormalizedField
private static Field selectionForNormalizedField(GraphQLSchema schema, java.lang.String objectTypeName, ExecutableNormalizedField executableNormalizedField, @NotNull @NotNull java.util.Map<ExecutableNormalizedField,QueryDirectives> normalizedFieldToQueryDirectives, VariableAccumulator variableAccumulator)
- Returns:
- Map of object type names to list of fields
-
selectionSetOrNullIfEmpty
@Nullable private static @Nullable SelectionSet selectionSetOrNullIfEmpty(java.util.List<Selection<?>> selections)
-
selectionSet
private static SelectionSet selectionSet(java.util.List<Field> fields)
-
createArguments
private static java.util.List<Argument> createArguments(ExecutableNormalizedField executableNormalizedField, VariableAccumulator variableAccumulator)
-
argValue
private static Value<?> argValue(ExecutableNormalizedField executableNormalizedField, java.lang.String argName, @Nullable @Nullable java.lang.Object value, VariableAccumulator variableAccumulator)
-
argValue
@NotNull private static @NotNull Value<?> argValue(ExecutableNormalizedField executableNormalizedField, java.lang.String argName, NormalizedInputValue normalizedInputValue, VariableAccumulator variableAccumulator)
-
getFieldDefinition
@NotNull private static @NotNull GraphQLFieldDefinition getFieldDefinition(GraphQLSchema schema, java.lang.String parentType, ExecutableNormalizedField nf)
-
getOperationType
@Nullable private static @Nullable GraphQLObjectType getOperationType(@NotNull @NotNull GraphQLSchema schema, @NotNull OperationDefinition.Operation operationKind)
-
-