Search in sources :

Example 1 with NodeParentTree

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);
    });
}
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 2 with NodeParentTree

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);
}
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 3 with NodeParentTree

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);
}
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)

Example 4 with NodeParentTree

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);
}
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) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) NamedNode(graphql.language.NamedNode) GraphqlElementParentTree(graphql.schema.GraphqlElementParentTree)

Example 5 with NodeParentTree

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);
}
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) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) NamedNode(graphql.language.NamedNode) GraphqlElementParentTree(graphql.schema.GraphqlElementParentTree)

Aggregations

Assert.assertNotNull (graphql.Assert.assertNotNull)5 Internal (graphql.Internal)5 ImmutableKit.map (graphql.collect.ImmutableKit.map)5 NamedNode (graphql.language.NamedNode)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 GraphQLSchemaElement (graphql.schema.GraphQLSchemaElement)5