Java Code Examples for graphql.schema.GraphQLInputObjectType#Builder

The following examples show how to use graphql.schema.GraphQLInputObjectType#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bootstrap.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
private void createGraphQLInputObjectType(InputType inputType) {
    GraphQLInputObjectType.Builder inputObjectTypeBuilder = GraphQLInputObjectType.newInputObject()
            .name(inputType.getName())
            .description(inputType.getDescription());

    // Fields
    if (inputType.hasFields()) {
        inputObjectTypeBuilder = inputObjectTypeBuilder
                .fields(createGraphQLInputObjectFieldsFromFields(inputType.getFields()));
        // Register this input for posible JsonB usage 
        JsonInputRegistry.register(inputType);
    }

    GraphQLInputObjectType graphQLInputObjectType = inputObjectTypeBuilder.build();
    inputMap.put(inputType.getClassName(), graphQLInputObjectType);
}
 
Example 2
Source File: FullTypeGenerator.java    From graphql-java-type-generator with MIT License 6 votes vote down vote up
protected GraphQLInputType generateInputType(Object object) {
    //An enum is a special case in both java and graphql,
    //and must be checked for while generating other kinds of types
    GraphQLEnumType enumType = generateEnumType(object);
    if (enumType != null) {
        return enumType;
    }
    
    List<GraphQLInputObjectField> fields = getInputFieldDefinitions(object);
    if (fields == null || fields.isEmpty()) {
        return null;
    }
    String typeName = getGraphQLTypeNameOrIdentityCode(object);
    
    GraphQLInputObjectType.Builder builder = new GraphQLInputObjectType.Builder();
    builder.name(typeName);
    builder.fields(fields);
    builder.description(getTypeDescription(object));
    return builder.build();
}
 
Example 3
Source File: AnnotationMapper.java    From graphql-spqr with Apache License 2.0 6 votes vote down vote up
@Override
protected GraphQLInputObjectType toGraphQLInputType(String typeName, AnnotatedType javaType, TypeMappingEnvironment env) {
    BuildContext buildContext = env.buildContext;

    GraphQLInputObjectType.Builder typeBuilder = newInputObject()
            .name(typeName)
            .description(buildContext.typeInfoGenerator.generateInputTypeDescription(javaType, buildContext.messageBundle));

    InputFieldBuilderParams params = InputFieldBuilderParams.builder()
            .withType(javaType)
            .withEnvironment(buildContext.globalEnvironment)
            .build();
    buildContext.inputFieldBuilders.getInputFields(params).forEach(field -> typeBuilder.field(env.operationMapper.toGraphQLInputField(field, buildContext)));

    return typeBuilder.build();
}
 
Example 4
Source File: ObjectTypeMapper.java    From graphql-spqr with Apache License 2.0 6 votes vote down vote up
@Override
public GraphQLInputObjectType toGraphQLInputType(String typeName, AnnotatedType javaType, TypeMappingEnvironment env) {
    BuildContext buildContext = env.buildContext;

    GraphQLInputObjectType.Builder typeBuilder = newInputObject()
            .name(typeName)
            .description(buildContext.typeInfoGenerator.generateInputTypeDescription(javaType, buildContext.messageBundle));

    InputFieldBuilderParams params = InputFieldBuilderParams.builder()
            .withType(javaType)
            .withEnvironment(buildContext.globalEnvironment)
            .withConcreteSubTypes(buildContext.abstractInputHandler.findConcreteSubTypes(ClassUtils.getRawType(javaType.getType()), buildContext))
            .build();
    buildContext.inputFieldBuilders.getInputFields(params).forEach(field -> typeBuilder.field(env.operationMapper.toGraphQLInputField(field, buildContext)));
    if (ClassUtils.isAbstract(javaType)) {
        createInputDisambiguatorField(javaType, buildContext).ifPresent(typeBuilder::field);
    }

    typeBuilder.withDirective(Directives.mappedType(javaType));
    buildContext.directiveBuilder.buildInputObjectTypeDirectives(javaType, buildContext.directiveBuilderParams()).forEach(directive ->
            typeBuilder.withDirective(env.operationMapper.toGraphQLDirective(directive, buildContext)));
    typeBuilder.comparatorRegistry(buildContext.comparatorRegistry(javaType));

    return typeBuilder.build();
}
 
Example 5
Source File: EnumMapToObjectTypeAdapter.java    From graphql-spqr with Apache License 2.0 6 votes vote down vote up
@Override
protected GraphQLInputObjectType toGraphQLInputType(String typeName, AnnotatedType javaType, TypeMappingEnvironment env) {
    BuildContext buildContext = env.buildContext;

    GraphQLInputObjectType.Builder builder = GraphQLInputObjectType.newInputObject()
            .name(typeName)
            .description(buildContext.typeInfoGenerator.generateInputTypeDescription(javaType, buildContext.messageBundle));

    @SuppressWarnings("rawtypes")
    Enum[] keys = (Enum[]) ClassUtils.getRawType(getElementType(javaType, 0).getType()).getEnumConstants();
    Arrays.stream(keys).forEach(enumValue -> {
        TypedElement element = new TypedElement(getElementType(javaType, 1), ClassUtils.getEnumConstantField(enumValue));
        builder.field(GraphQLInputObjectField.newInputObjectField()
                .name(enumMapper.getValueName(enumValue, buildContext.messageBundle))
                .description(enumMapper.getValueDescription(enumValue, buildContext.messageBundle))
                .type(env.forElement(element).toGraphQLInputType(element.getJavaType()))
                .build());
    });
    return builder.build();
}