use of graphql.schema.GraphQLInputObjectType in project graphql-java by graphql-java.
the class TraversalContext method enterImpl.
private void enterImpl(ObjectField objectField) {
GraphQLUnmodifiedType objectType = schemaUtil.getUnmodifiedType(getInputType());
GraphQLInputType inputType = null;
if (objectType instanceof GraphQLInputObjectType) {
GraphQLInputObjectType inputObjectType = (GraphQLInputObjectType) objectType;
GraphQLInputObjectField inputField = schema.getFieldVisibility().getFieldDefinition(inputObjectType, objectField.getName());
if (inputField != null)
inputType = inputField.getType();
}
addInputType(inputType);
}
use of graphql.schema.GraphQLInputObjectType in project graphql-java by graphql-java.
the class NoUnbrokenInputCycles method check.
private void check(GraphQLInputObjectType type, Set<GraphQLType> seen, List<String> path, SchemaValidationErrorCollector validationErrorCollector) {
if (seen.contains(type)) {
validationErrorCollector.addError(new SchemaValidationError(SchemaValidationErrorType.UnbrokenInputCycle, getErrorMessage(path)));
return;
}
seen.add(type);
for (GraphQLInputObjectField field : type.getFieldDefinitions()) {
if (field.getType() instanceof GraphQLNonNull) {
GraphQLType unwrapped = unwrapNonNull((GraphQLNonNull) field.getType());
if (unwrapped instanceof GraphQLInputObjectType) {
path = new ArrayList<>(path);
path.add(field.getName() + "!");
check((GraphQLInputObjectType) unwrapped, new HashSet<>(seen), path, validationErrorCollector);
}
}
}
}
use of graphql.schema.GraphQLInputObjectType in project graphql-java by graphql-java.
the class NoUnbrokenInputCycles method check.
@Override
public void check(GraphQLFieldDefinition fieldDef, SchemaValidationErrorCollector validationErrorCollector) {
for (GraphQLArgument argument : fieldDef.getArguments()) {
GraphQLInputType argumentType = argument.getType();
if (argumentType instanceof GraphQLInputObjectType) {
List<String> path = new ArrayList<>();
path.add(argumentType.getName());
check((GraphQLInputObjectType) argumentType, new HashSet<>(), path, validationErrorCollector);
}
}
}
use of graphql.schema.GraphQLInputObjectType in project graphql-java by graphql-java.
the class ReadmeExamples method mutationExample.
void mutationExample() {
GraphQLInputObjectType episodeType = GraphQLInputObjectType.newInputObject().name("Episode").field(newInputObjectField().name("episodeNumber").type(Scalars.GraphQLInt)).build();
GraphQLInputObjectType reviewInputType = GraphQLInputObjectType.newInputObject().name("ReviewInput").field(newInputObjectField().name("stars").type(Scalars.GraphQLString).name("commentary").type(Scalars.GraphQLString)).build();
GraphQLObjectType reviewType = newObject().name("Review").field(newFieldDefinition().name("stars").type(GraphQLString)).field(newFieldDefinition().name("commentary").type(GraphQLString)).build();
GraphQLObjectType createReviewForEpisodeMutation = newObject().name("CreateReviewForEpisodeMutation").field(newFieldDefinition().name("createReview").type(reviewType).argument(newArgument().name("episode").type(episodeType)).argument(newArgument().name("review").type(reviewInputType)).dataFetcher(mutationDataFetcher())).build();
GraphQLSchema schema = GraphQLSchema.newSchema().query(queryType).mutation(createReviewForEpisodeMutation).build();
}
use of graphql.schema.GraphQLInputObjectType in project graphql-java by graphql-java.
the class SchemaGeneratorHelper method buildValue.
public Object buildValue(Value value, GraphQLType requiredType) {
Object result = null;
if (requiredType instanceof GraphQLNonNull) {
requiredType = ((GraphQLNonNull) requiredType).getWrappedType();
}
if (requiredType instanceof GraphQLScalarType) {
result = parseLiteral(value, (GraphQLScalarType) requiredType);
} else if (value instanceof EnumValue && requiredType instanceof GraphQLEnumType) {
result = ((EnumValue) value).getName();
} else if (value instanceof ArrayValue && requiredType instanceof GraphQLList) {
ArrayValue arrayValue = (ArrayValue) value;
GraphQLType wrappedType = ((GraphQLList) requiredType).getWrappedType();
result = arrayValue.getValues().stream().map(item -> this.buildValue(item, wrappedType)).collect(Collectors.toList());
} else if (value instanceof ObjectValue && requiredType instanceof GraphQLInputObjectType) {
result = buildObjectValue((ObjectValue) value, (GraphQLInputObjectType) requiredType);
} else if (value != null && !(value instanceof NullValue)) {
Assert.assertShouldNeverHappen("cannot build value of %s from %s", requiredType.getName(), String.valueOf(value));
}
return result;
}
Aggregations