-
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.
Allow creating aliases for builtin types, using
typename
. (#133)
## Summary: This lets you write code like: ``` query x { # @genqlient(typename: "MyString") someStringField } ``` and genqlient will do ``` typename MyString string type x struct { someStringField MyString } ``` This was not difficult to implement, though it required introducing a new identifier type. The main difficulty I had was weird test failures, that it turns out was due to the tests putting a bunch of fields on the same line, so that the genqlient directive on the previous line applied to all of them, accidentally. This became a problem when `typename` suddenly started being respected for builtin types! I fixed it by just spreading out the queries a bit. Fixes #130 ## Test plan: make check Author: csilvers Reviewers: dnerdy, StevenACoffman, benjaminjkraft Required Reviewers: Approved By: StevenACoffman Checks: ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Lint, ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Lint Pull Request URL: #133
- Loading branch information
Showing
8 changed files
with
123 additions
and
48 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
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
query ConflictingTypeNames { | ||
# @genqlient(typename: "T") | ||
f { g } | ||
f { | ||
g | ||
} | ||
# @genqlient(typename: "T") | ||
otherF: f { g h } | ||
otherF: f { | ||
g | ||
h | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
# @genqlient(typename: "Resp") | ||
query TypeNames { | ||
# @genqlient(typename: "User") | ||
user { id name } | ||
user { | ||
id | ||
name | ||
} | ||
# @genqlient(typename: "Item") | ||
randomItem { id name } | ||
randomItem { | ||
id | ||
# @genqlient(typename: "NameType") | ||
name | ||
} | ||
# (ok to reuse the name as long as they match) | ||
# @genqlient(typename: "User") | ||
users { id name } | ||
users { | ||
id | ||
name | ||
} | ||
} |
16 changes: 9 additions & 7 deletions
16
generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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