use of graphql.schema.GraphQLInputType 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.GraphQLInputType in project graphql-java by graphql-java.
the class VariableTypesMatchRule method checkVariable.
@Override
public void checkVariable(VariableReference variableReference) {
VariableDefinition variableDefinition = variableDefinitionMap.get(variableReference.getName());
if (variableDefinition == null) {
return;
}
GraphQLType variableType = TypeFromAST.getTypeFromAST(getValidationContext().getSchema(), variableDefinition.getType());
if (variableType == null) {
return;
}
GraphQLInputType expectedType = getValidationContext().getInputType();
if (expectedType == null) {
// we must have a unknown variable say to not have a known type
return;
}
if (!variablesTypesMatcher.doesVariableTypesMatch(variableType, variableDefinition.getDefaultValue(), expectedType)) {
GraphQLType effectiveType = variablesTypesMatcher.effectiveType(variableType, variableDefinition.getDefaultValue());
String message = String.format("Variable type '%s' doesn't match expected type '%s'", GraphQLTypeUtil.getUnwrappedTypeName(effectiveType), GraphQLTypeUtil.getUnwrappedTypeName(expectedType));
addError(ValidationErrorType.VariableTypeMismatch, variableReference.getSourceLocation(), message);
}
}
use of graphql.schema.GraphQLInputType in project graphql-java by graphql-java.
the class SchemaGenerator method buildInputType.
private GraphQLInputType buildInputType(BuildContext buildCtx, Type rawType) {
TypeDefinition typeDefinition = buildCtx.getTypeDefinition(rawType);
TypeInfo typeInfo = TypeInfo.typeInfo(rawType);
GraphQLInputType inputType = buildCtx.hasInputType(typeDefinition);
if (inputType != null) {
return typeInfo.decorate(inputType);
}
if (buildCtx.stackContains(typeInfo)) {
// we have circled around so put in a type reference and fix it later
return typeInfo.decorate(typeRef(typeInfo.getName()));
}
buildCtx.push(typeInfo);
if (typeDefinition instanceof InputObjectTypeDefinition) {
inputType = buildInputObjectType(buildCtx, (InputObjectTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof EnumTypeDefinition) {
inputType = buildEnumType(buildCtx, (EnumTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof ScalarTypeDefinition) {
inputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition);
} else {
// typeDefinition is not a valid InputType
throw new NotAnInputTypeError(typeDefinition);
}
buildCtx.put(inputType);
buildCtx.pop();
return typeInfo.decorate(inputType);
}
use of graphql.schema.GraphQLInputType in project graphql-java by graphql-java.
the class SchemaGenerator method buildInputField.
private GraphQLInputObjectField buildInputField(BuildContext buildCtx, InputValueDefinition 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));
return fieldBuilder.build();
}
use of graphql.schema.GraphQLInputType in project graphql-java by graphql-java.
the class SchemaGenerator method buildArgument.
private GraphQLArgument buildArgument(BuildContext buildCtx, InputValueDefinition valueDefinition) {
GraphQLArgument.Builder builder = GraphQLArgument.newArgument();
builder.definition(valueDefinition);
builder.name(valueDefinition.getName());
builder.description(schemaGeneratorHelper.buildDescription(valueDefinition, valueDefinition.getDescription()));
GraphQLInputType inputType = buildInputType(buildCtx, valueDefinition.getType());
builder.type(inputType);
Value defaultValue = valueDefinition.getDefaultValue();
if (defaultValue != null) {
builder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType));
}
return builder.build();
}
Aggregations