use of graphql.schema.GraphQLType in project graphql-java by graphql-java.
the class FragmentsOnCompositeType method checkFragmentDefinition.
@Override
public void checkFragmentDefinition(FragmentDefinition fragmentDefinition) {
GraphQLType type = getValidationContext().getSchema().getType(fragmentDefinition.getTypeCondition().getName());
if (type == null)
return;
if (!(type instanceof GraphQLCompositeType)) {
String message = "Fragment type condition is invalid, must be on Object/Interface/Union";
addError(ValidationErrorType.InlineFragmentTypeConditionInvalid, fragmentDefinition.getSourceLocation(), message);
}
}
use of graphql.schema.GraphQLType in project graphql-java by graphql-java.
the class FragmentsOnCompositeType method checkInlineFragment.
@Override
public void checkInlineFragment(InlineFragment inlineFragment) {
if (inlineFragment.getTypeCondition() == null) {
return;
}
GraphQLType type = getValidationContext().getSchema().getType(inlineFragment.getTypeCondition().getName());
if (type == null)
return;
if (!(type instanceof GraphQLCompositeType)) {
String message = "Inline fragment type condition is invalid, must be on Object/Interface/Union";
addError(ValidationErrorType.InlineFragmentTypeConditionInvalid, inlineFragment.getSourceLocation(), message);
}
}
use of graphql.schema.GraphQLType in project graphql-java by graphql-java.
the class SchemaGenerator method buildAdditionalTypes.
/**
* We build the query / mutation / subscription path as a tree of referenced types
* but then we build the rest of the types specified and put them in as additional types
*
* @param buildCtx the context we need to work out what we are doing
*
* @return the additional types not referenced from the top level operations
*/
private Set<GraphQLType> buildAdditionalTypes(BuildContext buildCtx) {
Set<GraphQLType> additionalTypes = new HashSet<>();
TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
typeRegistry.types().values().forEach(typeDefinition -> {
TypeName typeName = new TypeName(typeDefinition.getName());
if (typeDefinition instanceof InputObjectTypeDefinition) {
if (buildCtx.hasInputType(typeDefinition) == null) {
additionalTypes.add(buildInputType(buildCtx, typeName));
}
} else {
if (buildCtx.hasOutputType(typeDefinition) == null) {
additionalTypes.add(buildOutputType(buildCtx, typeName));
}
}
});
return additionalTypes;
}
use of graphql.schema.GraphQLType 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