diff --git a/com.intuit.graphql.parent/com.intuit.graphql/src/com/intuit/graphql/validation/GraphQLValidator.java b/com.intuit.graphql.parent/com.intuit.graphql/src/com/intuit/graphql/validation/GraphQLValidator.java index f5f303c..52b05f6 100644 --- a/com.intuit.graphql.parent/com.intuit.graphql/src/com/intuit/graphql/validation/GraphQLValidator.java +++ b/com.intuit.graphql.parent/com.intuit.graphql/src/com/intuit/graphql/validation/GraphQLValidator.java @@ -11,7 +11,7 @@ * See * https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation */ -@ComposedChecks(validators = { DirectiveValidation.class, TypeSystemValidation.class, UnionTypeValidation.class }) +@ComposedChecks(validators = { DirectiveValidation.class, TypeSystemValidation.class, UnionTypeValidation.class, InputValueValidation.class }) public class GraphQLValidator extends AbstractGraphQLValidator { // public static final String INVALID_NAME = "invalidName"; diff --git a/com.intuit.graphql.parent/com.intuit.graphql/src/com/intuit/graphql/validation/InputValueValidation.java b/com.intuit.graphql.parent/com.intuit.graphql/src/com/intuit/graphql/validation/InputValueValidation.java new file mode 100644 index 0000000..9da4f43 --- /dev/null +++ b/com.intuit.graphql.parent/com.intuit.graphql/src/com/intuit/graphql/validation/InputValueValidation.java @@ -0,0 +1,33 @@ +package com.intuit.graphql.validation; + +import static com.intuit.graphql.utils.XtextTypeUtils.typeName; + +import java.util.Objects; + +import org.eclipse.xtext.validation.Check; + +import com.intuit.graphql.graphQL.InputObjectTypeDefinition; +import com.intuit.graphql.graphQL.InputValueDefinition; +import com.intuit.graphql.graphQL.NamedType; +import com.intuit.graphql.graphQL.ObjectType; + +class InputValueValidation extends BaseValidation { + + @Check + public void checkIfDefaultValuesConfirmsToNameTypes(InputValueDefinition inputValueDefinition) { + if (Objects.isNull(inputValueDefinition.getDefaultValue())) { + // since no default value exists + return; + } + NamedType namedType = inputValueDefinition.getNamedType(); + if (!isInputObjectType(namedType)) { + error("namedtype " + typeName(namedType) + " not confirms to inputObjectType.", inputValueDefinition); + } + + } + + private boolean isInputObjectType(NamedType namedType) { + return namedType instanceof ObjectType && ((ObjectType)namedType).getType() instanceof InputObjectTypeDefinition; + } + +}