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); }
.description("Criteria expression specification of "+namingStrategy.singularize(attribute.getName())+" attribute in entity " + attribute.getDeclaringType().getJavaType()) .field(GraphQLInputObjectField.newInputObjectField() .name("OR") .description("Logical OR criteria expression") .type(new GraphQLTypeReference(type)) .build() .name("AND") .description("Logical AND criteria expression") .type(new GraphQLTypeReference(type)) .build() .name(Criteria.EQ.name()) .description("Equals criteria") .type((GraphQLInputType) getAttributeType(attribute)) .build() .name(Criteria.NE.name()) .description("Not Equals criteria") .type((GraphQLInputType) getAttributeType(attribute)) .build() ); if(!attribute.getJavaType().equals(String.class)) { builder.field(GraphQLInputObjectField.newInputObjectField() .name(Criteria.LE.name()) .description("Less then or Equals criteria") .type((GraphQLInputType) getAttributeType(attribute)) .build()
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());
.field( newInputObjectField() .name("count") .description("Maximum number of builds to display") .type(GraphQLInt) .defaultValue(10) .build()
.name(arg.getName()) .description(arg.getDescription()) .type(arg.getType()) .defaultValue(arg.getDefaultValue()) .build()) .collect(Collectors.toList()); GraphQLInputObjectType inputObjectType = newInputObject() .name(mutation.getName() + "Input") .field(newInputObjectField() .name(CLIENT_MUTATION_ID) .type(new GraphQLNonNull(GraphQLString))) .fields(inputFields) .build();
.description("Where logical AND specification of the provided list of criteria expressions") .field(GraphQLInputObjectField.newInputObjectField() .name("OR") .description("Logical operation for expressions") .type(new GraphQLTypeReference(type)) .build() .name("AND") .description("Logical operation for expressions") .type(new GraphQLTypeReference(type)) .build()
.name(mpi.getName()) .type(graphQLInputType) .description(mpi.getDescription()) .defaultValue(defaultValue) .build(); graphQLInputObjectFields.add(graphQLInputObjectField); .name(inputObjectName + getGraphQLSchemaConfig().getInputObjectNamePrefix()) .field(newInputObjectField() .name(getGraphQLSchemaConfig().getClientMutationIdName()) .type(clientMutationIdType) .build()) .fields(graphQLInputObjectFields) .build();
@Override public List<GraphQLInputObjectField> getInputFields(Object object) { List<GraphQLInputObjectField> fieldDefs = new ArrayList<GraphQLInputObjectField>(); List<Object> fieldObjects = getFieldRepresentativeObjects(object); if (fieldObjects == null) { return fieldDefs; } Set<String> fieldNames = new HashSet<String>(); for (Object field : fieldObjects) { GraphQLInputObjectField.Builder fieldBuilder = getInputFieldDefinition(field); if (fieldBuilder == null) { continue; } GraphQLInputObjectField fieldDef = fieldBuilder.build(); //check for shadowed fields, where field "item" in superclass //is shadowed by field "item" in subclass if (fieldNames.contains(fieldDef.getName())) { continue; } fieldNames.add(fieldDef.getName()); fieldDefs.add(fieldDef); } return fieldDefs; }
/** * Creates a GraphQL Map Input type. GraphQL doesn't support this natively. We mimic * maps by creating a list of key/value pairs. * @param keyClazz The map key class * @param valueClazz The map value class * @return The created type. */ public GraphQLList classToInputMap(Class<?> keyClazz, Class<?> valueClazz) { String mapName = toValidNameName("__input__" + keyClazz.getName() + valueClazz.getCanonicalName() + MAP); if (mapConversions.containsKey(mapName)) { return mapConversions.get(mapName); } GraphQLInputType keyType = fetchScalarOrObjectInput(keyClazz); GraphQLInputType valueType = fetchScalarOrObjectInput(valueClazz); GraphQLList inputMap = new GraphQLList( newInputObject() .name(mapName) .field(newInputObjectField() .name(KEY) .type(keyType)) .field(newInputObjectField() .name(VALUE) .type(valueType)) .build() ); mapConversions.put(mapName, inputMap); return inputMap; }
/** * Creates a GraphQL Map Input type. GraphQL doesn't support this natively. We mimic * maps by creating a list of key/value pairs. * @param keyClazz The map key class * @param valueClazz The map value class * @return The created type. */ public GraphQLList classToInputMap(Class<?> keyClazz, Class<?> valueClazz) { String mapName = toValidNameName("__input__" + keyClazz.getName() + valueClazz.getCanonicalName() + MAP); if (mapConversions.containsKey(mapName)) { return mapConversions.get(mapName); } GraphQLInputType keyType = fetchScalarOrObjectInput(keyClazz); GraphQLInputType valueType = fetchScalarOrObjectInput(valueClazz); GraphQLList inputMap = new GraphQLList( newInputObject() .name(mapName) .field(newInputObjectField() .name(KEY) .type(keyType)) .field(newInputObjectField() .name(VALUE) .type(valueType)) .build() ); mapConversions.put(mapName, inputMap); return inputMap; }
private void createAddTodoMutation() { GraphQLInputObjectField textField = newInputObjectField() .name("text") .type(new GraphQLNonNull(GraphQLString)) .build(); List<GraphQLInputObjectField> inputFields = Arrays.asList(textField); GraphQLFieldDefinition todoEdge = newFieldDefinition() .name("todoEdge") .type(todoSchema.getTodosEdge()) .dataFetcher(environment -> { Map source = (Map) environment.getSource(); String todoId = (String) source.get("todoId"); Todo todo = todoSchema.getTodo(todoId); return new Edge(todo, todoSchema.getSimpleConnection().cursorForObjectInConnection(todo)); }) .build(); List<GraphQLFieldDefinition> outputFields = Arrays.asList(todoEdge, getViewerField()); DataFetcher mutate = environment -> { Map<String, Object> input = environment.getArgument("input"); String text = (String) input.get("text"); String newId = todoSchema.addTodo(text); Map<String, String> result = new LinkedHashMap<>(); result.put("clientMutationId", (String) input.get("clientMutationId")); result.put("todoId", newId); return result; }; addTodo = todoSchema.getRelay().mutationWithClientMutationId("AddTodo", "addTodo", inputFields, outputFields, mutate); }
/** * 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; }