Search in sources :

Example 6 with VariableDefinition

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);
    }
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) VariableDefinition(graphql.language.VariableDefinition) GraphQLType(graphql.schema.GraphQLType)

Example 7 with VariableDefinition

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);
}
Also used : TypeName(graphql.language.TypeName) VariableDefinition(graphql.language.VariableDefinition) NonNullType(graphql.language.NonNullType) ListType(graphql.language.ListType) FieldDefinition(graphql.language.FieldDefinition) InputValueDefinition(graphql.language.InputValueDefinition) OperationTypeDefinition(graphql.language.OperationTypeDefinition)

Example 8 with VariableDefinition

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;
}
Also used : VariableDefinition(graphql.language.VariableDefinition) NonNullType(graphql.language.NonNullType) ListType(graphql.language.ListType) FieldDefinition(graphql.language.FieldDefinition) InputValueDefinition(graphql.language.InputValueDefinition)

Aggregations

VariableDefinition (graphql.language.VariableDefinition)8 FieldDefinition (graphql.language.FieldDefinition)3 InputValueDefinition (graphql.language.InputValueDefinition)3 ListType (graphql.language.ListType)3 NonNullType (graphql.language.NonNullType)3 ArrayValue (graphql.language.ArrayValue)2 ObjectValue (graphql.language.ObjectValue)2 OperationDefinition (graphql.language.OperationDefinition)2 Value (graphql.language.Value)2 GraphQLType (graphql.schema.GraphQLType)2 ExecutionResultImpl (graphql.ExecutionResultImpl)1 GraphQLError (graphql.GraphQLError)1 InstrumentationExecutionParameters (graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters)1 BooleanValue (graphql.language.BooleanValue)1 EnumValue (graphql.language.EnumValue)1 FloatValue (graphql.language.FloatValue)1 FragmentDefinition (graphql.language.FragmentDefinition)1 IntValue (graphql.language.IntValue)1 NodeUtil (graphql.language.NodeUtil)1 NullValue (graphql.language.NullValue)1