use of graphql.language.VariableDefinition 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.language.VariableDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitTypeName.
// MARKER END: Here GraphqlOperation.g4 specific methods end
@Override
public Void visitTypeName(GraphqlParser.TypeNameContext ctx) {
TypeName typeName = new TypeName(ctx.name().getText());
newNode(typeName, ctx);
for (ContextEntry contextEntry : contextStack) {
if (contextEntry.value instanceof ListType) {
((ListType) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof NonNullType) {
((NonNullType) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof VariableDefinition) {
((VariableDefinition) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof FieldDefinition) {
((FieldDefinition) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof InputValueDefinition) {
((InputValueDefinition) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.contextProperty == ContextProperty.ObjectTypeDefinition) {
((ObjectTypeDefinition) contextEntry.value).getImplements().add(typeName);
break;
}
if (contextEntry.contextProperty == ContextProperty.UnionTypeDefinition) {
((UnionTypeDefinition) contextEntry.value).getMemberTypes().add(typeName);
break;
}
if (contextEntry.contextProperty == ContextProperty.OperationTypeDefinition) {
((OperationTypeDefinition) contextEntry.value).setType(typeName);
break;
}
}
return super.visitTypeName(ctx);
}
use of graphql.language.VariableDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitListType.
@Override
public Void visitListType(GraphqlParser.ListTypeContext ctx) {
ListType listType = new ListType();
newNode(listType, ctx);
for (ContextEntry contextEntry : contextStack) {
if (contextEntry.value instanceof ListType) {
((ListType) contextEntry.value).setType(listType);
break;
}
if (contextEntry.value instanceof NonNullType) {
((NonNullType) contextEntry.value).setType(listType);
break;
}
if (contextEntry.value instanceof VariableDefinition) {
((VariableDefinition) contextEntry.value).setType(listType);
break;
}
if (contextEntry.value instanceof FieldDefinition) {
((FieldDefinition) contextEntry.value).setType(listType);
break;
}
if (contextEntry.value instanceof InputValueDefinition) {
((InputValueDefinition) contextEntry.value).setType(listType);
break;
}
}
addContextProperty(ContextProperty.ListType, listType);
super.visitListType(ctx);
popContext();
return null;
}
Aggregations