Skip to content

Commit

Permalink
Migrated tests from GraphQL-JS regarding unique arguments (#1684)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Staib <michael@chillicream.com>
  • Loading branch information
PascalSenn and michaelstaib committed Apr 9, 2020
1 parent 9a8ef7c commit 6085a54
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 0 deletions.
145 changes: 145 additions & 0 deletions src/HotChocolate/Core/test/Validation.Tests/ArgumentNamesRuleTests.cs
Expand Up @@ -104,5 +104,150 @@ ... multipleArgsReverseOrder
}
");
}

[Fact]
public void NoArgumentsOnField()
{
// arrange
ExpectValid(@"
{
fieldWithArg
}
");
}

[Fact]
public void NoArgumentsOnDirective()
{
// arrange
ExpectValid(@"
{
fieldWithArg @directive
}
");
}

[Fact]
public void ArgumentOnField()
{
// arrange
ExpectValid(@"
{
fieldWithArg(arg: ""value"")
}
");
}

[Fact]
public void ArgumentOnDirective()
{
// arrange
ExpectValid(@"
{
fieldWithArg @directive(arg: ""value"")
}
");
}

[Fact]
public void SameArgumentOnTwoFields()
{
// arrange
ExpectValid(@"
{
one: fieldWithArg(arg: ""value"")
two: fieldWithArg(arg: ""value"")
}
");
}

[Fact]
public void SameArgumentOnFieldAndDirective()
{
// arrange
ExpectValid(@"
{
fieldWithArg(arg: ""value"") @directive(arg: ""value"")
}
");
}

[Fact]
public void SameArgumentOnTwoDirectives()
{
// arrange
ExpectValid(@"
{
fieldWithArg @directive1(arg: ""value"") @directive2(arg: ""value"")
}
");
}

[Fact]
public void MultipleFieldArguments()
{
// arrange
ExpectValid(@"
{
fieldWithArg(arg1: ""value"", arg2: ""value"", arg3: ""value"")
}
");
}

[Fact]
public void MultipleDirectiveArguments()
{
// arrange
ExpectValid(@"
{
fieldWithArg @directive(arg1: ""value"", arg2: ""value"", arg3: ""value"")
}
");
}

[Fact]
public void DuplicateFieldArguments()
{
// arrange
ExpectErrors(@"
{
fieldWithArg(arg1: ""value"", arg1: ""value"")
}
");
}

[Fact]
public void ManyDuplicateFieldArguments()
{
// arrange
ExpectErrors(@"
{
fieldWithArg(arg1: ""value"", arg1: ""value"", arg1: ""value"")
}
");
}

[Fact]
public void DuplicateDirectiveArguments()
{
// arrange
ExpectErrors(@"
{
fieldWithArg @directive(arg1: ""value"", arg1: ""value"")
}
");
}

[Fact]
public void ManyDuplicateDirectiveArguments()
{
// arrange
ExpectErrors(@"
{
fieldWithArg @directive(arg1: ""value"", arg1: ""value"", arg1: ""value"")
}
");
}

}
}
10 changes: 10 additions & 0 deletions src/HotChocolate/Core/test/Validation.Tests/Models/Query.cs
Expand Up @@ -41,5 +41,15 @@ public string[] GetStringList()
{
return null;
}

public string GetFieldWithArg(
string arg,
string arg1,
string arg2,
string arg3,
string arg4)
{
return null;
}
}
}
@@ -0,0 +1,37 @@
using HotChocolate.Types;

namespace HotChocolate.Validation.Types
{
public class CustomDirectiveType
: DirectiveType
{
private readonly string _name;

public CustomDirectiveType(string name)
{
_name = name;
}

protected override void Configure(
IDirectiveTypeDescriptor descriptor)
{
descriptor.Repeatable();

descriptor.Name(_name);

descriptor.Location(DirectiveLocation.Field);

descriptor.Argument("arg")
.Type<StringType>();
descriptor.Argument("arg1")
.Type<StringType>();
descriptor.Argument("arg2")
.Type<StringType>();
descriptor.Argument("arg3")
.Type<StringType>();
descriptor.Argument("arg4")
.Type<StringType>();

}
}
}
@@ -1,4 +1,5 @@
using HotChocolate.Language;
using HotChocolate.Types;
using HotChocolate.Validation.Types;

#nullable enable
Expand Down Expand Up @@ -47,6 +48,9 @@ public static Schema CreateSchema()
c.RegisterType<ComplexInput3Type>();
c.RegisterType<InvalidScalar>();
c.RegisterDirective<ComplexDirective>();
c.RegisterDirective(new CustomDirectiveType("directive"));
c.RegisterDirective(new CustomDirectiveType("directive1"));
c.RegisterDirective(new CustomDirectiveType("directive2"));
});
}
}
Expand Down
@@ -0,0 +1,21 @@
[
{
"Message": "More than one argument with the same name in an argument set is ambiguous and invalid.",
"Code": null,
"Path": [
"fieldWithArg"
],
"Locations": [
{
"Line": 3,
"Column": 60
}
],
"Exception": null,
"Extensions": {
"directive": "directive",
"argument": "arg1",
"specifiedBy": "http://spec.graphql.org/June2018/#sec-Argument-Uniqueness"
}
}
]
@@ -0,0 +1,20 @@
[
{
"Message": "More than one argument with the same name in an argument set is ambiguous and invalid.",
"Code": null,
"Path": [],
"Locations": [
{
"Line": 3,
"Column": 49
}
],
"Exception": null,
"Extensions": {
"type": "Query",
"field": "fieldWithArg",
"argument": "arg1",
"specifiedBy": "http://spec.graphql.org/June2018/#sec-Argument-Uniqueness"
}
}
]
@@ -0,0 +1,40 @@
[
{
"Message": "More than one argument with the same name in an argument set is ambiguous and invalid.",
"Code": null,
"Path": [
"fieldWithArg"
],
"Locations": [
{
"Line": 3,
"Column": 60
}
],
"Exception": null,
"Extensions": {
"directive": "directive",
"argument": "arg1",
"specifiedBy": "http://spec.graphql.org/June2018/#sec-Argument-Uniqueness"
}
},
{
"Message": "More than one argument with the same name in an argument set is ambiguous and invalid.",
"Code": null,
"Path": [
"fieldWithArg"
],
"Locations": [
{
"Line": 3,
"Column": 75
}
],
"Exception": null,
"Extensions": {
"directive": "directive",
"argument": "arg1",
"specifiedBy": "http://spec.graphql.org/June2018/#sec-Argument-Uniqueness"
}
}
]
@@ -0,0 +1,38 @@
[
{
"Message": "More than one argument with the same name in an argument set is ambiguous and invalid.",
"Code": null,
"Path": [],
"Locations": [
{
"Line": 3,
"Column": 49
}
],
"Exception": null,
"Extensions": {
"type": "Query",
"field": "fieldWithArg",
"argument": "arg1",
"specifiedBy": "http://spec.graphql.org/June2018/#sec-Argument-Uniqueness"
}
},
{
"Message": "More than one argument with the same name in an argument set is ambiguous and invalid.",
"Code": null,
"Path": [],
"Locations": [
{
"Line": 3,
"Column": 64
}
],
"Exception": null,
"Extensions": {
"type": "Query",
"field": "fieldWithArg",
"argument": "arg1",
"specifiedBy": "http://spec.graphql.org/June2018/#sec-Argument-Uniqueness"
}
}
]

0 comments on commit 6085a54

Please sign in to comment.