use of graphql.language.NodeParentTree in project graphql-java by graphql-java.
the class SchemaGeneratorDirectiveHelper method wireFields.
private List<GraphQLFieldDefinition> wireFields(GraphQLFieldsContainer fieldsContainer, NamedNode<?> fieldsContainerNode, Parameters params) {
return map(fieldsContainer.getFieldDefinitions(), fieldDefinition -> {
// and for each argument in the fieldDefinition run the wiring for them - and note that they can change
List<GraphQLArgument> startingArgs = fieldDefinition.getArguments();
List<GraphQLArgument> newArgs = wireArguments(fieldDefinition, fieldsContainer, fieldsContainerNode, params, fieldDefinition);
if (isNotTheSameObjects(startingArgs, newArgs)) {
// they may have changed the arguments to the fieldDefinition so reflect that
fieldDefinition = fieldDefinition.transform(builder -> builder.clearArguments().arguments(newArgs));
}
NodeParentTree<NamedNode<?>> nodeParentTree = buildAstTree(fieldsContainerNode, fieldDefinition.getDefinition());
GraphqlElementParentTree elementParentTree = buildRuntimeTree(fieldsContainer, fieldDefinition);
Parameters fieldParams = params.newParams(fieldDefinition, fieldsContainer, nodeParentTree, elementParentTree);
// now for each fieldDefinition run the new wiring and capture the results
return onField(fieldDefinition, fieldParams);
});
}
use of graphql.language.NodeParentTree in project graphql-java by graphql-java.
the class SchemaGeneratorDirectiveHelper method onEnum.
public GraphQLEnumType onEnum(final GraphQLEnumType enumType, Parameters params) {
List<GraphQLEnumValueDefinition> startingEnumValues = enumType.getValues();
List<GraphQLEnumValueDefinition> newEnumValues = map(startingEnumValues, enumValueDefinition -> {
NodeParentTree<NamedNode<?>> nodeParentTree = buildAstTree(enumType.getDefinition(), enumValueDefinition.getDefinition());
GraphqlElementParentTree elementParentTree = buildRuntimeTree(enumType, enumValueDefinition);
Parameters fieldParams = params.newParams(nodeParentTree, elementParentTree);
// now for each field run the new wiring and capture the results
return onEnumValue(enumValueDefinition, fieldParams);
});
GraphQLEnumType newEnumType = enumType;
if (isNotTheSameObjects(startingEnumValues, newEnumValues)) {
newEnumType = enumType.transform(builder -> builder.clearValues().values(newEnumValues));
}
NodeParentTree<NamedNode<?>> nodeParentTree = buildAstTree(newEnumType.getDefinition());
GraphqlElementParentTree elementParentTree = buildRuntimeTree(newEnumType);
Parameters newParams = params.newParams(nodeParentTree, elementParentTree);
return wireDirectives(params, newEnumType, newEnumType.getDirectives(), newEnumType.getAppliedDirectives(), (outputElement, directives, appliedDirectives, registeredDirective) -> new SchemaDirectiveWiringEnvironmentImpl<>(outputElement, directives, appliedDirectives, registeredDirective, newParams), SchemaDirectiveWiring::onEnum);
}
use of graphql.language.NodeParentTree in project graphql-java by graphql-java.
the class SchemaGeneratorDirectiveHelper method onInterface.
public GraphQLInterfaceType onInterface(GraphQLInterfaceType interfaceType, Parameters params) {
List<GraphQLFieldDefinition> startingFields = interfaceType.getFieldDefinitions();
List<GraphQLFieldDefinition> newFields = wireFields(interfaceType, interfaceType.getDefinition(), params);
GraphQLInterfaceType newInterfaceType = interfaceType;
if (isNotTheSameObjects(startingFields, newFields)) {
newInterfaceType = interfaceType.transform(builder -> builder.clearFields().fields(newFields));
}
NodeParentTree<NamedNode<?>> nodeParentTree = buildAstTree(newInterfaceType.getDefinition());
GraphqlElementParentTree elementParentTree = buildRuntimeTree(newInterfaceType);
Parameters newParams = params.newParams(newInterfaceType, nodeParentTree, elementParentTree);
return wireDirectives(params, newInterfaceType, newInterfaceType.getDirectives(), newInterfaceType.getAppliedDirectives(), (outputElement, directives, appliedDirectives, registeredDirective) -> new SchemaDirectiveWiringEnvironmentImpl<>(outputElement, directives, appliedDirectives, registeredDirective, newParams), SchemaDirectiveWiring::onInterface);
}
use of graphql.language.NodeParentTree in project graphql-java by graphql-java.
the class SchemaGeneratorDirectiveHelper method onInputObjectType.
public GraphQLInputObjectType onInputObjectType(GraphQLInputObjectType inputObjectType, Parameters params) {
List<GraphQLInputObjectField> startingFields = inputObjectType.getFieldDefinitions();
List<GraphQLInputObjectField> newFields = map(startingFields, inputField -> {
NodeParentTree<NamedNode<?>> nodeParentTree = buildAstTree(inputObjectType.getDefinition(), inputField.getDefinition());
GraphqlElementParentTree elementParentTree = buildRuntimeTree(inputObjectType, inputField);
Parameters fieldParams = params.newParams(nodeParentTree, elementParentTree);
// now for each field run the new wiring and capture the results
return onInputObjectField(inputField, fieldParams);
});
GraphQLInputObjectType newInputObjectType = inputObjectType;
if (isNotTheSameObjects(startingFields, newFields)) {
newInputObjectType = inputObjectType.transform(builder -> builder.clearFields().fields(newFields));
}
NodeParentTree<NamedNode<?>> nodeParentTree = buildAstTree(newInputObjectType.getDefinition());
GraphqlElementParentTree elementParentTree = buildRuntimeTree(newInputObjectType);
Parameters newParams = params.newParams(nodeParentTree, elementParentTree);
return wireDirectives(params, newInputObjectType, newInputObjectType.getDirectives(), newInputObjectType.getAppliedDirectives(), (outputElement, directives, appliedDirectives, registeredDirective) -> new SchemaDirectiveWiringEnvironmentImpl<>(outputElement, directives, appliedDirectives, registeredDirective, newParams), SchemaDirectiveWiring::onInputObjectType);
}
use of graphql.language.NodeParentTree in project graphql-java by graphql-java.
the class SchemaGeneratorDirectiveHelper method onObject.
public GraphQLObjectType onObject(GraphQLObjectType objectType, Parameters params) {
List<GraphQLFieldDefinition> startingFields = objectType.getFieldDefinitions();
List<GraphQLFieldDefinition> newFields = wireFields(objectType, objectType.getDefinition(), params);
GraphQLObjectType newObjectType = objectType;
if (isNotTheSameObjects(startingFields, newFields)) {
newObjectType = objectType.transform(builder -> builder.clearFields().fields(newFields));
}
NodeParentTree<NamedNode<?>> nodeParentTree = buildAstTree(newObjectType.getDefinition());
GraphqlElementParentTree elementParentTree = buildRuntimeTree(newObjectType);
Parameters newParams = params.newParams(newObjectType, nodeParentTree, elementParentTree);
return wireDirectives(params, newObjectType, newObjectType.getDirectives(), newObjectType.getAppliedDirectives(), (outputElement, directives, appliedDirectives, registeredDirective) -> new SchemaDirectiveWiringEnvironmentImpl<>(outputElement, directives, appliedDirectives, registeredDirective, newParams), SchemaDirectiveWiring::onObject);
}
Aggregations