forked from graph-quilt/graphql-xtext
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added InputValueValidation issue: graph-quilt#24
- Loading branch information
Nitish Jain
committed
Oct 30, 2023
1 parent
8222de9
commit 966e0f9
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...hql.parent/com.intuit.graphql/src/com/intuit/graphql/validation/InputValueValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |