Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject the use of both typename and bind #172

Merged
merged 1 commit into from
Feb 10, 2022

Conversation

benjaminjkraft
Copy link
Collaborator

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

I have:

  • Written a clear PR title and description (above)
  • Signed the Khan Academy CLA (hehe I realized I actually should go and sign this now!)
  • Added tests covering my changes, if applicable
  • Included a link to the issue fixed, if applicable (n/a)
  • Included documentation, for new features
  • Added an entry to the changelog

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
Copy link
Member

@csilvers csilvers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! I'm so glad you did this instead of me, I'm sure I would have made a hash of it. All the changes look good to me, though if there was another place you needed to validate but missed, I'm unlikely to have noticed.

@benjaminjkraft benjaminjkraft mentioned this pull request Feb 10, 2022
6 tasks
@benjaminjkraft
Copy link
Collaborator Author

Yeah, I'm only 90% sure I thought of all the ways it could happen, but I decided that's way better than 0%!

@benjaminjkraft benjaminjkraft merged commit 67f2575 into main Feb 10, 2022
@benjaminjkraft benjaminjkraft deleted the benkraft.typename-and-bind branch February 10, 2022 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants