Skip to content

Commit

Permalink
added InputValueValidation issue: graph-quilt#24
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitish Jain committed Oct 30, 2023
1 parent 8222de9 commit 966e0f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit 966e0f9

Please sign in to comment.