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: https://github.com/Khan/genqlient/pull/133
This commit is contained in:
+7
-5
@@ -76,11 +76,13 @@ client_getter: "github.com/you/yourpkg.GetClient"
|
||||
# A map from GraphQL type name to Go fully-qualified type name to override
|
||||
# the Go type genqlient will use for this GraphQL type.
|
||||
#
|
||||
# This is primarily used for custom scalars, or to map builtin scalars to
|
||||
# a nonstandard type. By default, builtin scalars are mapped to the
|
||||
# obvious Go types (String and ID to string, Int to int, Float to float64,
|
||||
# and Boolean to bool), but this setting will extend or override those
|
||||
# mappings.
|
||||
# This is primarily used for custom scalars, or to map builtin scalars
|
||||
# to a nonstandard type that is defined elsewhere. By default,
|
||||
# builtin scalars are mapped to the obvious Go types (String and ID to
|
||||
# string, Int to int, Float to float64, and Boolean to bool), but this
|
||||
# setting will extend or override those mappings. (See also
|
||||
# @genqlient(typename: ...), which can be used to map builtin scalars
|
||||
# to a nonstandard type that genqlient defines for you.)
|
||||
#
|
||||
# genqlient does not validate these types in any way; they must define
|
||||
# whatever logic is needed (MarshalJSON/UnmarshalJSON or JSON tags) to
|
||||
|
||||
Reference in New Issue
Block a user