forked from ChilliCream/graphql-platform
-
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.
Finalized Validation Rules (ChilliCream#221)
- Loading branch information
1 parent
11518c7
commit f9685e9
Showing
60 changed files
with
3,071 additions
and
77 deletions.
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
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
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
59 changes: 59 additions & 0 deletions
59
src/Core.Tests/Validation/DirectivesAreDefinedRuleTests.cs
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,59 @@ | ||
using HotChocolate.Language; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Validation | ||
{ | ||
public class DirectivesAreDefinedRuleTests | ||
: ValidationTestBase | ||
{ | ||
public DirectivesAreDefinedRuleTests() | ||
: base(new DirectivesAreDefinedRule()) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void SupportedDirective() | ||
{ | ||
// arrange | ||
Schema schema = ValidationUtils.CreateSchema(); | ||
DocumentNode query = Parser.Default.Parse(@" | ||
{ | ||
dog { | ||
name @skip(if: true) | ||
} | ||
} | ||
"); | ||
|
||
// act | ||
QueryValidationResult result = Rule.Validate(schema, query); | ||
|
||
// assert | ||
Assert.False(result.HasErrors); | ||
} | ||
|
||
[Fact] | ||
public void UnsupportedDirective() | ||
{ | ||
// arrange | ||
Schema schema = ValidationUtils.CreateSchema(); | ||
DocumentNode query = Parser.Default.Parse(@" | ||
{ | ||
dog { | ||
name @foo(bar: true) | ||
} | ||
} | ||
"); | ||
|
||
// act | ||
QueryValidationResult result = Rule.Validate(schema, query); | ||
|
||
// assert | ||
Assert.True(result.HasErrors); | ||
Assert.Collection(result.Errors, | ||
t => Assert.Equal( | ||
"The specified directive `foo` " + | ||
"is not supported by the current schema.", | ||
t.Message)); | ||
} | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
src/Core.Tests/Validation/FragmentSpreadIsPossibleRuleTests.cs
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,114 @@ | ||
using HotChocolate.Language; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Validation | ||
{ | ||
public class FragmentSpreadIsPossibleRuleTests | ||
: ValidationTestBase | ||
{ | ||
public FragmentSpreadIsPossibleRuleTests() | ||
: base(new FragmentSpreadIsPossibleRule()) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void FragmentDoesNotMatchType() | ||
{ | ||
// arrange | ||
Schema schema = ValidationUtils.CreateSchema(); | ||
DocumentNode query = Parser.Default.Parse(@" | ||
{ | ||
dog { | ||
...fragmentDoesNotMatchType | ||
} | ||
} | ||
fragment fragmentDoesNotMatchType on Human { | ||
name | ||
} | ||
"); | ||
|
||
// act | ||
QueryValidationResult result = Rule.Validate(schema, query); | ||
|
||
// assert | ||
Assert.True(result.HasErrors); | ||
Assert.Collection(result.Errors, | ||
t => Assert.Equal(t.Message, | ||
"The parent type does not match the type condition on " + | ||
"the fragment `fragmentDoesNotMatchType`.")); | ||
} | ||
|
||
[Fact] | ||
public void InterfaceTypeDoesMatch() | ||
{ | ||
// arrange | ||
Schema schema = ValidationUtils.CreateSchema(); | ||
DocumentNode query = Parser.Default.Parse(@" | ||
{ | ||
dog { | ||
...interfaceTypeDoesMatch | ||
} | ||
} | ||
fragment interfaceTypeDoesMatch on Pet { | ||
name | ||
} | ||
"); | ||
|
||
// act | ||
QueryValidationResult result = Rule.Validate(schema, query); | ||
|
||
// assert | ||
Assert.False(result.HasErrors); | ||
} | ||
|
||
[Fact] | ||
public void UnionTypeDoesMatch() | ||
{ | ||
// arrange | ||
Schema schema = ValidationUtils.CreateSchema(); | ||
DocumentNode query = Parser.Default.Parse(@" | ||
{ | ||
dog { | ||
...unionTypeDoesMatch | ||
} | ||
} | ||
fragment unionTypeDoesMatch on CatOrDog { | ||
name | ||
} | ||
"); | ||
|
||
// act | ||
QueryValidationResult result = Rule.Validate(schema, query); | ||
|
||
// assert | ||
Assert.False(result.HasErrors); | ||
} | ||
|
||
[Fact] | ||
public void ObjectTypeDoesMatch() | ||
{ | ||
// arrange | ||
Schema schema = ValidationUtils.CreateSchema(); | ||
DocumentNode query = Parser.Default.Parse(@" | ||
{ | ||
dog { | ||
...objectTypeDoesMatch | ||
} | ||
} | ||
fragment objectTypeDoesMatch on Dog { | ||
name | ||
} | ||
"); | ||
|
||
// act | ||
QueryValidationResult result = Rule.Validate(schema, query); | ||
|
||
// assert | ||
Assert.False(result.HasErrors); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/Core.Tests/Validation/FragmentSpreadTargetDefinedRuleTests.cs
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,62 @@ | ||
using HotChocolate.Language; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Validation | ||
{ | ||
public class FragmentSpreadTargetDefinedRuleTests | ||
: ValidationTestBase | ||
{ | ||
public FragmentSpreadTargetDefinedRuleTests() | ||
: base(new FragmentSpreadTargetDefinedRule()) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void UndefinedFragment() | ||
{ | ||
// arrange | ||
Schema schema = ValidationUtils.CreateSchema(); | ||
DocumentNode query = Parser.Default.Parse(@" | ||
{ | ||
dog { | ||
...undefinedFragment | ||
} | ||
} | ||
"); | ||
|
||
// act | ||
QueryValidationResult result = Rule.Validate(schema, query); | ||
|
||
// assert | ||
Assert.True(result.HasErrors); | ||
Assert.Collection(result.Errors, | ||
t => Assert.Equal(t.Message, | ||
"The specified fragment `undefinedFragment` does not exist.")); | ||
} | ||
|
||
[Fact] | ||
public void DefinedFragment() | ||
{ | ||
// arrange | ||
Schema schema = ValidationUtils.CreateSchema(); | ||
DocumentNode query = Parser.Default.Parse(@" | ||
{ | ||
dog { | ||
...definedFragment | ||
} | ||
} | ||
fragment definedFragment on Dog | ||
{ | ||
barkVolume | ||
} | ||
"); | ||
|
||
// act | ||
QueryValidationResult result = Rule.Validate(schema, query); | ||
|
||
// assert | ||
Assert.False(result.HasErrors); | ||
} | ||
} | ||
} |
Oops, something went wrong.