-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reject the use of both typename and bind
In #133, Craig added support for a new use of typename, where it applies to a scalar and means that genqlient should generate a named type, e.g. `# @genqlient(typename: "MyString")` on a node of type string will generate and use `type MyString string`. But this gets a bit confusing if you mix it with `bind`; should `typename: "MyString", bind: "int32"` generate `type MyString int32`, or should one override the other, or what? Of course in practice you're not likely to write that all in one place, but you could via a global binding, or a `for` directive, and in that case probably it was a mistake. In #138, we looked at making them work together correctly, but it added complexity and got even more confusing. So instead, here, we just ban it; we can always add it back if it proves useful. (Or, you can make the `typename` win over a global binding by locally unbinding it via `bind: "-"`.) This required changes in surprisingly many places; I already knew the directive-validation code was due for a refactor but that will happen some other day. The tests show that it works, in any case. Interestingly, this problem actually could have arisen for a struct binding already, before #133. But all the same reasons it's confusing seem to apply, so I just banned it there too. This is technically a breaking change although I doubt anyone will hit it. Test plan: make check
- Loading branch information
1 parent
8aa56aa
commit f975bbf
Showing
13 changed files
with
81 additions
and
0 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
7 changes: 7 additions & 0 deletions
7
generate/testdata/errors/ConflictingTypeNameAndForFieldBind.graphql
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,7 @@ | ||
# @genqlient(for: "User.name", bind: "[]byte") | ||
query ConflictingTypeNameAndGlobalBind { | ||
user { | ||
# @genqlient(typename: "MyID") | ||
name | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
generate/testdata/errors/ConflictingTypeNameAndForFieldBind.schema.graphql
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,8 @@ | ||
type Query { | ||
user: User | ||
} | ||
|
||
type User { | ||
id: ID! | ||
name: String! | ||
} |
8 changes: 8 additions & 0 deletions
8
generate/testdata/errors/ConflictingTypeNameAndGlobalBind.graphql
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,8 @@ | ||
query ConflictingTypeNameAndGlobalBind { | ||
user { | ||
# @genqlient(typename: "OtherScalar") | ||
name | ||
} | ||
} | ||
|
||
|
10 changes: 10 additions & 0 deletions
10
generate/testdata/errors/ConflictingTypeNameAndGlobalBind.schema.graphql
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,10 @@ | ||
type Query { | ||
user: User | ||
} | ||
|
||
type User { | ||
id: ID! | ||
name: ValidScalar! | ||
} | ||
|
||
scalar ValidScalar |
6 changes: 6 additions & 0 deletions
6
generate/testdata/errors/ConflictingTypeNameAndLocalBind.graphql
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,6 @@ | ||
query ConflictingTypeNameAndGlobalBind { | ||
user { | ||
# @genqlient(bind: "[]byte", typename: "MyID") | ||
name | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
generate/testdata/errors/ConflictingTypeNameAndLocalBind.schema.graphql
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,8 @@ | ||
type Query { | ||
user: User | ||
} | ||
|
||
type User { | ||
id: ID! | ||
name: String! | ||
} |
1 change: 1 addition & 0 deletions
1
generate/testdata/snapshots/TestGenerateErrors-ConflictingTypeNameAndForFieldBind-graphql
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 @@ | ||
testdata/errors/ConflictingTypeNameAndForFieldBind.graphql:5: typename and bind may not be used together |
1 change: 1 addition & 0 deletions
1
generate/testdata/snapshots/TestGenerateErrors-ConflictingTypeNameAndGlobalBind-graphql
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 @@ | ||
testdata/errors/ConflictingTypeNameAndGlobalBind.schema.graphql:8: typename option conflicts with global binding for ValidScalar; use `bind: "-"` to override it |
1 change: 1 addition & 0 deletions
1
generate/testdata/snapshots/TestGenerateErrors-ConflictingTypeNameAndLocalBind-graphql
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 @@ | ||
testdata/errors/ConflictingTypeNameAndLocalBind.graphql:4: typename and bind may not be used together |