private GraphQLInputObjectField buildInputField(BuildContext buildCtx, InputValueDefinition fieldDef) { buildCtx.enterNode(fieldDef); GraphQLInputObjectField.Builder fieldBuilder = GraphQLInputObjectField.newInputObjectField(); fieldBuilder.definition(fieldDef); fieldBuilder.name(fieldDef.getName()); fieldBuilder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription())); // currently the spec doesnt allow deprecations on InputValueDefinitions but it should! //fieldBuilder.deprecate(buildDeprecationReason(fieldDef.getDirectives())); GraphQLInputType inputType = buildInputType(buildCtx, fieldDef.getType()); fieldBuilder.type(inputType); Value defaultValue = fieldDef.getDefaultValue(); if (defaultValue != null) { fieldBuilder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType)); } fieldBuilder.withDirectives( buildDirectives(fieldDef.getDirectives(), emptyList(), INPUT_FIELD_DEFINITION, buildCtx.getDirectiveDefinitions()) ); GraphQLInputObjectField inputObjectField = fieldBuilder.build(); inputObjectField = directiveBehaviour.onInputObjectField(inputObjectField, buildCtx.mkBehaviourParams()); return buildCtx.exitNode(inputObjectField); }
private GraphQLFieldDefinition buildRelayMutation(Method method, ProcessingElementsContainer container, GraphQLFieldDefinition.Builder builder, GraphQLOutputType outputType, List<GraphQLArgument> args) { GraphQLFieldDefinition relayFieldDefinition; if (!(outputType instanceof GraphQLObjectType || outputType instanceof GraphQLInterfaceType)) { throw new RuntimeException("outputType should be an object or an interface"); } StringBuilder titleBuffer = new StringBuilder(method.getName()); titleBuffer.setCharAt(0, Character.toUpperCase(titleBuffer.charAt(0))); String title = titleBuffer.toString(); List<GraphQLFieldDefinition> fieldDefinitions = outputType instanceof GraphQLObjectType ? ((GraphQLObjectType) outputType).getFieldDefinitions() : ((GraphQLInterfaceType) outputType).getFieldDefinitions(); relayFieldDefinition = container.getRelay().mutationWithClientMutationId(title, method.getName(), args.stream(). map(t -> newInputObjectField().name(t.getName()).type(t.getType()).description(t.getDescription()).build()). collect(Collectors.toList()), fieldDefinitions, new StaticDataFetcher(null)); builder.argument(relayFieldDefinition.getArguments()).type(relayFieldDefinition.getType()); return relayFieldDefinition; }
relay = RELAY_TYPES.mutationWithClientMutationId(title, method.getName(), args.stream(). map(t -> newInputObjectField().name(t.getName()).type(t.getType()).description(t.getDescription()).build()). collect(Collectors.toList()), fieldDefinitions, null); builder.argument(relay.getArguments());
newInputObjectField() .name("count") .description("Maximum number of builds to display") .type(GraphQLInt) .defaultValue(10)
.map(arg -> GraphQLInputObjectField.newInputObjectField() .name(arg.getName()) .description(arg.getDescription()) .type(arg.getType()) .defaultValue(arg.getDefaultValue())
.name(mpi.getName()) .type(graphQLInputType) .description(mpi.getDescription()) .defaultValue(defaultValue) .build();
.field(GraphQLInputObjectField.newInputObjectField() .name("OR") .description("Logical operation for expressions") .type(new GraphQLTypeReference(type)) .build() .description("Logical operation for expressions") .type(new GraphQLTypeReference(type)) .build()
/** * May return null should this field be disallowed * @param object * @return */ protected GraphQLInputObjectField.Builder getInputFieldDefinition( final Object object) { String fieldName = getFieldName(object); GraphQLInputType fieldType = (GraphQLInputType) getTypeOfField(object, TypeKind.INPUT_OBJECT); if (fieldName == null || fieldType == null) { return null; } String fieldDescription = getFieldDescription(object); String fieldDefaultValue = getFieldDefaultValue(object); logger.debug("GraphQL field will be of type [{}] and name [{}] with description [{}]", fieldType, fieldName, fieldDescription); GraphQLInputObjectField.Builder fieldBuilder = newInputObjectField() .name(fieldName) .type(fieldType) .description(fieldDescription) .defaultValue(fieldDefaultValue); return fieldBuilder; }
private GraphQLInputType getInputType(GraphQLOutputType outputType) { if (GraphQLInputType.class.isAssignableFrom(outputType.getClass())) { return (GraphQLInputType) outputType; } else if (outputType instanceof GraphQLObjectType) { GraphQLObjectType objectType = (GraphQLObjectType) outputType; final String inputTypeName; inputTypeName = String.format("%s%s%s", objectType.getName(), this.getTypeNamingStrategy().getDelimiter(), this.getTypeNamingStrategy().getInputTypePostfix()); GraphQLInputObjectType.Builder rv = GraphQLInputObjectType.newInputObject().name(inputTypeName); rv.description(((GraphQLObjectType) outputType).getDescription()); for (GraphQLFieldDefinition field : objectType.getFieldDefinitions()) { rv.field(GraphQLInputObjectField.newInputObjectField() .name(field.getName()) .type(getInputType(field.getType())) .description(field.getDescription()) .build()); } GraphQLInputType type = rv.build(); inputTypes.add(type); return type; } else { throw new RuntimeException(String.format("Unknown output type %s", outputType.toString())); } }
private GraphQLInputObjectField buildInputField(BuildContext buildCtx, InputValueDefinition fieldDef) { buildCtx.enterNode(fieldDef); GraphQLInputObjectField.Builder fieldBuilder = GraphQLInputObjectField.newInputObjectField(); fieldBuilder.definition(fieldDef); fieldBuilder.name(fieldDef.getName()); fieldBuilder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription())); // currently the spec doesnt allow deprecations on InputValueDefinitions but it should! //fieldBuilder.deprecate(buildDeprecationReason(fieldDef.getDirectives())); GraphQLInputType inputType = buildInputType(buildCtx, fieldDef.getType()); fieldBuilder.type(inputType); Value defaultValue = fieldDef.getDefaultValue(); if (defaultValue != null) { fieldBuilder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType)); } fieldBuilder.withDirectives( buildDirectives(fieldDef.getDirectives(), emptyList(), INPUT_FIELD_DEFINITION, buildCtx.getDirectiveDefinitions()) ); GraphQLInputObjectField inputObjectField = fieldBuilder.build(); inputObjectField = directiveBehaviour.onInputObjectField(inputObjectField, buildCtx.mkBehaviourParams()); return buildCtx.exitNode(inputObjectField); }
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(); }
private GraphQLInputType mapEntry(GraphQLInputType keyType, GraphQLInputType valueType, BuildContext buildContext) { String typeName = "mapEntry_" + getTypeName(keyType) + "_" + getTypeName(valueType) + "_input"; if (buildContext.typeCache.contains(typeName)) { return new GraphQLTypeReference(typeName); } buildContext.typeCache.register(typeName); return newInputObject() .name(typeName) .description("Map entry input") .field(newInputObjectField() .name("key") .description("Map key input") .type(keyType) .build()) .field(newInputObjectField() .name("value") .description("Map value input") .type(valueType) .build()) .build(); }
/** * Maps a single field/property to a GraphQL input field. * * @param inputField The field/property to map to a GraphQL input field * @param buildContext The shared context containing all the global information needed for mapping * * @return GraphQL input field representing the given field/property */ public GraphQLInputObjectField toGraphQLInputField(InputField inputField, BuildContext buildContext) { GraphQLInputObjectField.Builder builder = newInputObjectField() .name(inputField.getName()) .description(inputField.getDescription()) .type(toGraphQLInputType(inputField.getJavaType(), buildContext)) .withDirective(Directives.mappedInputField(inputField)) .withDirectives(toGraphQLDirectives(inputField.getTypedElement(), buildContext.directiveBuilder::buildInputFieldDefinitionDirectives, buildContext)) .defaultValue(inputField.getDefaultValue()); return buildContext.transformers.transform(builder.build(), inputField, this, buildContext); }
public GraphQLInputObjectField buildGraphQLInputObjectField(DfsContext dfsContext, Field field, Class<?> implClass) { ResolvableTypeAccessor resolvableTypeAccessor = ResolvableTypeAccessor.forField(field, implClass); Object defaultValue = invokeMethodByName(dfsContext, implClass, resolvableTypeAccessor.getGraphQLInDefaultValueProviderMethodName()); defaultValue = evaluateSpElExpression(dfsContext, implClass, null, resolvableTypeAccessor.getGraphQLInDefaultValueSpel(), defaultValue); GraphQLInputObjectField graphQLInputObjectField = GraphQLInputObjectField.newInputObjectField() .name(resolvableTypeAccessor.getName()) .description(resolvableTypeAccessor.getDescription()) .defaultValue(defaultValue) .type(buildGraphQLInputTypeFromMethodParam(dfsContext, resolvableTypeAccessor)) .build(); return graphQLInputObjectField; }
static GraphQLInputObjectField formField(String fieldName, String description, GraphQLInputType inputType) { return newInputObjectField() .name(fieldName) .description(description) .type(inputType) .build(); }
@Override protected GraphQLInputObjectType toGraphQLInputType(String typeName, AnnotatedType javaType, OperationMapper operationMapper, BuildContext buildContext) { GraphQLInputObjectType.Builder builder = GraphQLInputObjectType.newInputObject() .name(typeName) .description(buildContext.typeInfoGenerator.generateInputTypeDescription(javaType, buildContext.messageBundle)); Enum[] keys = (Enum[]) ClassUtils.getRawType(getElementType(javaType, 0).getType()).getEnumConstants(); Arrays.stream(keys).forEach(enumValue -> builder.field(GraphQLInputObjectField.newInputObjectField() .name(enumMapper.getValueName(enumValue, buildContext.messageBundle)) .description(enumMapper.getValueDescription(enumValue, buildContext.messageBundle)) .type(operationMapper.toGraphQLInputType(getElementType(javaType, 1), buildContext)) .build())); return builder.build(); }
public GraphQLInputObjectField getInputField(Method method, ProcessingElementsContainer container) throws GraphQLAnnotationsException { GraphQLInputObjectField.Builder builder = newInputObjectField(); builder.name(new MethodNameBuilder(method).alwaysPrettify(alwaysPrettify).build()); TypeFunction typeFunction = getTypeFunction(method, container); GraphQLInputType inputType = (GraphQLInputType) new MethodTypeBuilder(method, typeFunction, container, true).build(); return builder.type(inputType).description(new DescriptionBuilder(method).build()).build(); }
public GraphQLInputObjectField getInputField(Field field, ProcessingElementsContainer container) throws GraphQLAnnotationsException { GraphQLInputObjectField.Builder builder = newInputObjectField(); builder.name(new FieldNameBuilder(field).alwaysPrettify(alwaysPrettify).build()); TypeFunction typeFunction = getTypeFunction(field, container); GraphQLType graphQLType = typeFunction.buildType(true, field.getType(), field.getAnnotatedType(), container); return builder.type((GraphQLInputType) graphQLType).description(new DescriptionBuilder(field).build()).build(); }
private GraphQLInputObjectField formField(String fieldName, String description) { return newInputObjectField() .name(fieldName) .description(description) .type(GraphQLString) .build(); }
private GraphQLInputObjectField getWhereInputField(Attribute<?,?> attribute) { GraphQLType type = getWhereAttributeType(attribute); String description = getSchemaDescription(attribute.getJavaMember()); if (type instanceof GraphQLInputType) { return GraphQLInputObjectField.newInputObjectField() .name(attribute.getName()) .description(description) .type((GraphQLInputType) type) .build(); } throw new IllegalArgumentException("Attribute " + attribute.getName() + " cannot be mapped as an Input Argument"); }