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

Fix a bug in type-name collapsing introduced by #71 #110

Merged
merged 1 commit into from
Sep 23, 2021

Conversation

benjaminjkraft
Copy link
Collaborator

Summary:

We typically name our types OperationFieldTypeFieldType, but if a
type's name matches the preceding field-name, we omit the type-name.
In #71 I changed the behavior such that we no longer do that in the case
where the type's name matches some suffix of the name-so-far that's
longer than just the leaf field-name.

This was semi-intentional; I assumed it didn't matter and would be more
predictable this way. But it turns out that was a feature, both in the
sense that almost any change to the type-name-generator is breaking, and
in the sense that it made the names uglier. Plus, now that we have
better conflict-detection (#94), the possibility that some tricksy
type-names could cause problems is no longer as much of an issue, so we
can be a little less careful here. (Although I think this is no less
safe than before; the field-names are the important part.) So in this
commit I revert the change.

Specifically, this comes up a lot at Khan where we do

mutation ForcePhantom {
    forcePhantom {     # type: ForcePhantom
        error { ... }  # type: ForcePhantomError
    }
}

Before #71, and again after this change, we'll generate
ForcePhantomForcePhantomError for error; before we'd generate
ForcePhantomForcePhantomErrorForcePhantomError.

Issue: #109

Test plan:

make tesc

We typically name our types `OperationFieldTypeFieldType`, but if a
type's name matches the preceding field-name, we omit the type-name.
In #71 I changed the behavior such that we no longer do that in the case
where the type's name matches some suffix of the name-so-far that's
longer than just the leaf field-name.

This was semi-intentional; I assumed it didn't matter and would be more
predictable this way.  But it turns out that was a feature, both in the
sense that almost any change to the type-name-generator is breaking, and
in the sense that it made the names uglier.  Plus, now that we have
better conflict-detection (#94), the possibility that some tricksy
type-names could cause problems is no longer as much of an issue, so we
can be a little less careful here.  (Although I think this is no less
safe than before; the field-names are the important part.)  So in this
commit I revert the change.

Specifically, this comes up a lot at Khan where we do
```
mutation ForcePhantom {
    forcePhantom {     # type: ForcePhantom
        error { ... }  # type: ForcePhantomError
    }
}
```
Before #71, and again after this change, we'll generate
`ForcePhantomForcePhantomError` for `error`; before we'd generate
`ForcePhantomForcePhantomErrorForcePhantomError`.

Issue: #109

Test plan:
make tesc

Reviewers: csilvers, marksandstrom, steve, mahtab, adam, miguel, jvoll
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.

OK! I'm not the best person to review, but it's a small enough change, and I think the review is in the semantics really, which seem fine to me.

@benjaminjkraft benjaminjkraft merged commit ab1aaed into main Sep 23, 2021
@benjaminjkraft benjaminjkraft deleted the benkraft.typename-fix branch September 23, 2021 00:00
@csilvers
Copy link
Member

This is merged into main but I'm not seeing any differences. I ran

   go get github.com/Khan/genqlient@main

which updated it to v0.1.1-0.20210917010932-f72933fa0e0b which seems plausible, but when I re-run make genqlient I don't see any type-names change.

@csilvers
Copy link
Member

(Ah, nope, f729 is not the latest commit. I wonder what I have to do to get go get to get the latest.)

@csilvers
Copy link
Member

Ah, I got it by doing go get github.com/Khan/genqlient@ab... directly.

@benjaminjkraft
Copy link
Collaborator Author

Possibly just a caching issue? Specifying the commit should work anyway.

@dnerdy
Copy link
Contributor

dnerdy commented Sep 23, 2021

The change looks good to me.

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.

Type-name collapsing not working in some cases
3 participants