If requested, validate binding-types get the right fields (#70)
## Summary: One sharp edge of the new `bindings` setting (when used for composite types) is this: the (presumably struct) type to which you're binding may expect to have particular fields, but it's GraphQL so you could have requested some other set of fields. Now, if you ask us, we check. Specifically, I've added a new setting under the `bindings` items, which says: everywhere we query this must select these fields. (Or use its own inline `# @genqlient(bind: ...)`.) It must select exactly those fields, in order, no more, no less. This was fairly easy to implement; actually comparing the selections was surprisingly much code but it's all pretty straightforward. ## Test plan: make check Author: benjaminjkraft Reviewers: dnerdy, aberkan, csilvers, MiguelCastillo Required Reviewers: Approved by: dnerdy Checks: ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Test (1.13), ✅ Lint, ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Test (1.13), ✅ Lint Pull request URL: https://github.com/Khan/genqlient/pull/70
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package errors
|
||||
|
||||
const _ = `# @genqlient
|
||||
query GetPokemonWrongFields {
|
||||
pokemon { species }
|
||||
}
|
||||
`
|
||||
@@ -0,0 +1,3 @@
|
||||
query GetPokemonWrongFields {
|
||||
pokemon { species species }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
type Query {
|
||||
pokemon: Pokemon
|
||||
}
|
||||
|
||||
type Pokemon {
|
||||
species: String!
|
||||
level: Int!
|
||||
}
|
||||
+2
-1
@@ -8,7 +8,8 @@ query GetPokemonSiblings($input: PokemonInput!) {
|
||||
roles
|
||||
name
|
||||
# this is mapped globally to internal/testutil.Pokemon:
|
||||
pokemon { species level }
|
||||
# note field ordering matters, but whitespace shouldn't.
|
||||
pokemon { species level }
|
||||
# this overrides said mapping:
|
||||
# @genqlient(bind: "-")
|
||||
genqlientPokemon: pokemon { species level }
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
invalid selection for type-binding GetPokemonWrongFieldsPokemon: testdata/errors/BindingWithIncorrectSelection.schema.graphql:2: expected 2 fields, got 1
|
||||
+1
@@ -0,0 +1 @@
|
||||
invalid selection for type-binding GetPokemonWrongFieldsPokemon: testdata/errors/BindingWithIncorrectSelection.graphql:2: expected field 1 to be level, got species
|
||||
Reference in New Issue
Block a user