Reject the use of both typename and bind (#172)

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
This commit is contained in:
Ben Kraft
2022-02-09 16:54:31 -08:00
committed by GitHub
parent 8aa56aacf1
commit 67f2575cae
13 changed files with 81 additions and 0 deletions
+1
View File
@@ -23,6 +23,7 @@ When releasing a new version:
### Breaking changes:
- The `Config` fields `Schema` and `Operations` are now both of type `StringList`. This does not affect configuration via `genqlient.yaml`, only via the Go API.
- The `typename` and `bind` options may no longer be combined; doing so will now result in an error. In practice, any such use was likely in error (and the rules for which would win were confusing and undocumented).
### New features:
+4
View File
@@ -226,6 +226,10 @@ directive genqlient(
# Note that unlike most directives, if applied to the entire operation,
# typename affects the overall response type, rather than being propagated
# down to all child fields (which would cause conflicts).
#
# To avoid confusion, typename may not be combined with local or global
# bindings; to use typename instead of a global binding do
# `typename: "MyTypeName", bind: "-"`.
typename: String
# Multiple genqlient directives are allowed in the same location, as long as