Search in sources :

Example 1 with GraphqlElementParentTree

use of graphql.schema.GraphqlElementParentTree in project graphql-java by graphql-java.

the class SchemaGeneratorDirectiveHelper method onUnion.

public GraphQLUnionType onUnion(GraphQLUnionType element, Parameters params) {
    NodeParentTree<NamedNode<?>> nodeParentTree = buildAstTree(element.getDefinition());
    GraphqlElementParentTree elementParentTree = buildRuntimeTree(element);
    Parameters newParams = params.newParams(nodeParentTree, elementParentTree);
    return wireDirectives(params, element, element.getDirectives(), element.getAppliedDirectives(), (outputElement, directives, appliedDirectives, registeredDirective) -> new SchemaDirectiveWiringEnvironmentImpl<>(outputElement, directives, appliedDirectives, registeredDirective, newParams), SchemaDirectiveWiring::onUnion);
}
Also used : NamedNode(graphql.language.NamedNode) GraphqlElementParentTree(graphql.schema.GraphqlElementParentTree)

Example 2 with GraphqlElementParentTree

use of graphql.schema.GraphqlElementParentTree in project graphql-java by graphql-java.

the class SchemaGeneratorDirectiveHelper method wireArguments.

private List<GraphQLArgument> wireArguments(GraphQLFieldDefinition fieldDefinition, GraphQLFieldsContainer fieldsContainer, NamedNode<?> fieldsContainerNode, Parameters params, GraphQLFieldDefinition field) {
    return map(field.getArguments(), argument -> {
        NodeParentTree<NamedNode<?>> nodeParentTree = buildAstTree(fieldsContainerNode, field.getDefinition(), argument.getDefinition());
        GraphqlElementParentTree elementParentTree = buildRuntimeTree(fieldsContainer, field, argument);
        Parameters argParams = params.newParams(fieldDefinition, fieldsContainer, nodeParentTree, elementParentTree);
        return onArgument(argument, argParams);
    });
}
Also used : NamedNode(graphql.language.NamedNode) GraphqlElementParentTree(graphql.schema.GraphqlElementParentTree)

Example 3 with GraphqlElementParentTree

use of graphql.schema.GraphqlElementParentTree 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);
    });
}
Also used : GraphQLSchemaElement(graphql.schema.GraphQLSchemaElement) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) Internal(graphql.Internal) GraphQLDirectiveContainer(graphql.schema.GraphQLDirectiveContainer) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLScalarType(graphql.schema.GraphQLScalarType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLUnionType(graphql.schema.GraphQLUnionType) HashMap(java.util.HashMap) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) Deque(java.util.Deque) GraphQLAppliedDirective(graphql.schema.GraphQLAppliedDirective) NodeParentTree(graphql.language.NodeParentTree) Map(java.util.Map) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLDirective(graphql.schema.GraphQLDirective) GraphQLArgument(graphql.schema.GraphQLArgument) List(java.util.List) GraphqlElementParentTree(graphql.schema.GraphqlElementParentTree) ImmutableKit.map(graphql.collect.ImmutableKit.map) Assert.assertNotNull(graphql.Assert.assertNotNull) NamedNode(graphql.language.NamedNode) GraphQLEnumType(graphql.schema.GraphQLEnumType) ArrayDeque(java.util.ArrayDeque) GraphQLFieldsContainer(graphql.schema.GraphQLFieldsContainer) NamedNode(graphql.language.NamedNode) GraphQLArgument(graphql.schema.GraphQLArgument) GraphqlElementParentTree(graphql.schema.GraphqlElementParentTree)

Example 4 with GraphqlElementParentTree

use of graphql.schema.GraphqlElementParentTree 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);
}
Also used : GraphQLSchemaElement(graphql.schema.GraphQLSchemaElement) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) Internal(graphql.Internal) GraphQLDirectiveContainer(graphql.schema.GraphQLDirectiveContainer) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLScalarType(graphql.schema.GraphQLScalarType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLUnionType(graphql.schema.GraphQLUnionType) HashMap(java.util.HashMap) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) Deque(java.util.Deque) GraphQLAppliedDirective(graphql.schema.GraphQLAppliedDirective) NodeParentTree(graphql.language.NodeParentTree) Map(java.util.Map) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLDirective(graphql.schema.GraphQLDirective) GraphQLArgument(graphql.schema.GraphQLArgument) List(java.util.List) GraphqlElementParentTree(graphql.schema.GraphqlElementParentTree) ImmutableKit.map(graphql.collect.ImmutableKit.map) Assert.assertNotNull(graphql.Assert.assertNotNull) NamedNode(graphql.language.NamedNode) GraphQLEnumType(graphql.schema.GraphQLEnumType) ArrayDeque(java.util.ArrayDeque) GraphQLFieldsContainer(graphql.schema.GraphQLFieldsContainer) GraphQLEnumType(graphql.schema.GraphQLEnumType) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) NamedNode(graphql.language.NamedNode) GraphqlElementParentTree(graphql.schema.GraphqlElementParentTree)

Example 5 with GraphqlElementParentTree

use of graphql.schema.GraphqlElementParentTree 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);
}
Also used : GraphQLSchemaElement(graphql.schema.GraphQLSchemaElement) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) Internal(graphql.Internal) GraphQLDirectiveContainer(graphql.schema.GraphQLDirectiveContainer) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLScalarType(graphql.schema.GraphQLScalarType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLUnionType(graphql.schema.GraphQLUnionType) HashMap(java.util.HashMap) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) Deque(java.util.Deque) GraphQLAppliedDirective(graphql.schema.GraphQLAppliedDirective) NodeParentTree(graphql.language.NodeParentTree) Map(java.util.Map) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLDirective(graphql.schema.GraphQLDirective) GraphQLArgument(graphql.schema.GraphQLArgument) List(java.util.List) GraphqlElementParentTree(graphql.schema.GraphqlElementParentTree) ImmutableKit.map(graphql.collect.ImmutableKit.map) Assert.assertNotNull(graphql.Assert.assertNotNull) NamedNode(graphql.language.NamedNode) GraphQLEnumType(graphql.schema.GraphQLEnumType) ArrayDeque(java.util.ArrayDeque) GraphQLFieldsContainer(graphql.schema.GraphQLFieldsContainer) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) NamedNode(graphql.language.NamedNode) GraphqlElementParentTree(graphql.schema.GraphqlElementParentTree) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType)

Aggregations

NamedNode (graphql.language.NamedNode)8 GraphqlElementParentTree (graphql.schema.GraphqlElementParentTree)8 Assert.assertNotNull (graphql.Assert.assertNotNull)5 Internal (graphql.Internal)5 ImmutableKit.map (graphql.collect.ImmutableKit.map)5 NodeParentTree (graphql.language.NodeParentTree)5 GraphQLAppliedDirective (graphql.schema.GraphQLAppliedDirective)5 GraphQLArgument (graphql.schema.GraphQLArgument)5 GraphQLCodeRegistry (graphql.schema.GraphQLCodeRegistry)5 GraphQLDirective (graphql.schema.GraphQLDirective)5 GraphQLDirectiveContainer (graphql.schema.GraphQLDirectiveContainer)5 GraphQLEnumType (graphql.schema.GraphQLEnumType)5 GraphQLEnumValueDefinition (graphql.schema.GraphQLEnumValueDefinition)5 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)5 GraphQLFieldsContainer (graphql.schema.GraphQLFieldsContainer)5 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)5 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)5 GraphQLInterfaceType (graphql.schema.GraphQLInterfaceType)5 GraphQLObjectType (graphql.schema.GraphQLObjectType)5 GraphQLScalarType (graphql.schema.GraphQLScalarType)5