Search in sources :

Example 11 with GraphQLInputType

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

the class SchemaGeneratorHelper method buildDirectiveArgument.

private GraphQLArgument buildDirectiveArgument(Argument arg) {
    GraphQLArgument.Builder builder = GraphQLArgument.newArgument();
    builder.name(arg.getName());
    GraphQLInputType inputType = buildDirectiveInputType(arg.getValue());
    builder.type(inputType);
    builder.defaultValue(buildValue(arg.getValue(), inputType));
    return builder.build();
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLArgument(graphql.schema.GraphQLArgument)

Example 12 with GraphQLInputType

use of graphql.schema.GraphQLInputType in project admin-console-beta by connexta.

the class GraphQLTransformInput method fieldTypeToGraphQLInputType.

@SuppressWarnings("squid:S00112")
public GraphQLInputType fieldTypeToGraphQLInputType(Field field) {
    if (inputTypesProvider.isTypePresent(field.getFieldType())) {
        return inputTypesProvider.getType(field.getFieldType());
    }
    GraphQLInputType type = null;
    if (field instanceof ObjectField) {
        type = objectFieldToGraphQLInputType((ObjectField) field);
    } else if (field instanceof EnumField) {
        type = transformEnum.enumFieldToGraphQLEnumType((EnumField) field);
    } else if (field instanceof ListField) {
        try {
            type = new GraphQLList(fieldTypeToGraphQLInputType(((ListField<Field>) field).createListEntry()));
        } catch (Exception e) {
            throw new RuntimeException("Unable to build field list content type for input type: " + field.getFieldName());
        }
    } else if (field instanceof ScalarField) {
        type = transformScalars.resolveScalarType((ScalarField) field);
    }
    if (type == null) {
        throw new RuntimeException("Error transforming input field to GraphQLInputType. Unknown field type: " + field.getClass());
    }
    inputTypesProvider.addType(field.getFieldType(), type);
    return type;
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLList(graphql.schema.GraphQLList) EnumField(org.codice.ddf.admin.api.fields.EnumField) Field(org.codice.ddf.admin.api.Field) ObjectField(org.codice.ddf.admin.api.fields.ObjectField) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) EnumField(org.codice.ddf.admin.api.fields.EnumField) ListField(org.codice.ddf.admin.api.fields.ListField) ScalarField(org.codice.ddf.admin.api.fields.ScalarField) ScalarField(org.codice.ddf.admin.api.fields.ScalarField) ObjectField(org.codice.ddf.admin.api.fields.ObjectField) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) ListField(org.codice.ddf.admin.api.fields.ListField)

Example 13 with GraphQLInputType

use of graphql.schema.GraphQLInputType in project ontrack by nemerosa.

the class GraphQLBeanConverter method asInputType.

public static GraphQLInputType asInputType(Class<?> type) {
    GraphQLInputObjectType.Builder builder = newInputObject().name(type.getSimpleName());
    // Gets the properties for the type
    for (PropertyDescriptor descriptor : BeanUtils.getPropertyDescriptors(type)) {
        if (descriptor.getReadMethod() != null) {
            String name = descriptor.getName();
            String description = descriptor.getShortDescription();
            GraphQLInputType scalarType = getScalarType(descriptor.getPropertyType());
            if (scalarType != null) {
                builder = builder.field(field -> field.name(name).description(description).type(scalarType));
            }
        }
    }
    // OK
    return builder.build();
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLObjectType(graphql.schema.GraphQLObjectType) ImmutableSet(com.google.common.collect.ImmutableSet) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLScalarType(graphql.schema.GraphQLScalarType) GQLTypeCache(net.nemerosa.ontrack.graphql.schema.GQLTypeCache) Collection(java.util.Collection) LocalDateTime(java.time.LocalDateTime) GraphQLInputType(graphql.schema.GraphQLInputType) Set(java.util.Set) InvocationTargetException(java.lang.reflect.InvocationTargetException) HashSet(java.util.HashSet) Scalars(graphql.Scalars) PropertyDescriptor(java.beans.PropertyDescriptor) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Method(java.lang.reflect.Method) BeanUtils(org.springframework.beans.BeanUtils) GraphQLInputObjectType.newInputObject(graphql.schema.GraphQLInputObjectType.newInputObject) PropertyDescriptor(java.beans.PropertyDescriptor) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType)

Aggregations

GraphQLInputType (graphql.schema.GraphQLInputType)13 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)4 GraphQLArgument (graphql.schema.GraphQLArgument)3 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)3 Value (graphql.language.Value)2 GraphQLList (graphql.schema.GraphQLList)2 GraphQLType (graphql.schema.GraphQLType)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Scalars (graphql.Scalars)1 EnumTypeDefinition (graphql.language.EnumTypeDefinition)1 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)1 InterfaceTypeDefinition (graphql.language.InterfaceTypeDefinition)1 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)1 OperationTypeDefinition (graphql.language.OperationTypeDefinition)1 ScalarTypeDefinition (graphql.language.ScalarTypeDefinition)1 TypeDefinition (graphql.language.TypeDefinition)1 UnionTypeDefinition (graphql.language.UnionTypeDefinition)1