-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
9046c14d135e7e0785b6a43cd0e0ceef7e8773b4 [9046c14] Parents: 657fbbba26 Author: Lee Byron <[email protected]> Date: 24 September 2015 at 7:49:45 AM SGT [RFC] Move input field uniqueness validator This proposes moving input field uniqueness assertion from the parser to the validator. This simplifies the parser and allows these errors to be reported as part of the collection of validation errors which is actually more valuable. A follow-up RFC against the spec will be added
- Loading branch information
Showing
4 changed files
with
125 additions
and
22 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
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,65 @@ | ||
package graphql_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/graphql-go/graphql" | ||
"github.com/graphql-go/graphql/gqlerrors" | ||
"github.com/graphql-go/graphql/testutil" | ||
) | ||
|
||
func TestValidate_UniqueInputFieldNames_InputObjectWithFields(t *testing.T) { | ||
testutil.ExpectPassesRule(t, graphql.UniqueInputFieldNamesRule, ` | ||
{ | ||
field(arg: { f: true }) | ||
} | ||
`) | ||
} | ||
func TestValidate_UniqueInputFieldNames_SameInputObjectWithinTwoArgs(t *testing.T) { | ||
testutil.ExpectPassesRule(t, graphql.UniqueInputFieldNamesRule, ` | ||
{ | ||
field(arg1: { f: true }, arg2: { f: true }) | ||
} | ||
`) | ||
} | ||
func TestValidate_UniqueInputFieldNames_MultipleInputObjectFields(t *testing.T) { | ||
testutil.ExpectPassesRule(t, graphql.UniqueInputFieldNamesRule, ` | ||
{ | ||
field(arg: { f1: "value", f2: "value", f3: "value" }) | ||
} | ||
`) | ||
} | ||
func TestValidate_UniqueInputFieldNames_AllowsForNestedInputObjectsWithSimilarFields(t *testing.T) { | ||
testutil.ExpectPassesRule(t, graphql.UniqueInputFieldNamesRule, ` | ||
{ | ||
field(arg: { | ||
deep: { | ||
deep: { | ||
id: 1 | ||
} | ||
id: 1 | ||
} | ||
id: 1 | ||
}) | ||
} | ||
`) | ||
} | ||
func TestValidate_UniqueInputFieldNames_DuplicateInputObjectFields(t *testing.T) { | ||
testutil.ExpectFailsRule(t, graphql.UniqueInputFieldNamesRule, ` | ||
{ | ||
field(arg: { f1: "value", f1: "value" }) | ||
} | ||
`, []gqlerrors.FormattedError{ | ||
testutil.RuleError(`There can be only one input field named "f1".`, 3, 22, 3, 35), | ||
}) | ||
} | ||
func TestValidate_UniqueInputFieldNames_ManyDuplicateInputObjectFields(t *testing.T) { | ||
testutil.ExpectFailsRule(t, graphql.UniqueInputFieldNamesRule, ` | ||
{ | ||
field(arg: { f1: "value", f1: "value", f1: "value" }) | ||
} | ||
`, []gqlerrors.FormattedError{ | ||
testutil.RuleError(`There can be only one input field named "f1".`, 3, 22, 3, 35), | ||
testutil.RuleError(`There can be only one input field named "f1".`, 3, 22, 3, 48), | ||
}) | ||
} |