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: premarshal structs get generated with omitempty tag #267

Merged
merged 5 commits into from
May 5, 2023

Conversation

kevinmichaelchen
Copy link
Contributor

@kevinmichaelchen kevinmichaelchen commented May 4, 2023

This PR addresses a bug described in #263

Basically, whenever a struct involves a custom genqlient binding, a secondary "premarshal" struct gets generated.

The bug was that this "premarshal" struct was not propagating the omitempty JSON tags, which was resulting in unexpected behavior.

The fix involved a few changed lines in the Go template, and a few changes in the unit tests.

I have:

  • Written a clear PR title and description (above)
  • Signed the Khan Academy CLA
  • Added tests covering my changes, if applicable
  • Included a link to the issue fixed, if applicable
  • Included documentation, for new features
  • Added an entry to the changelog

@benjaminjkraft
Copy link
Collaborator

Thanks! I'll take a closer look later but a few quick comments now:

  • Since this is a bugfix it probably doesn't need any documentation changes, just a brief changelog entry summarizing and linking to the issue.
  • If it's not too hard, it would be nice to write an integration test that fails without this change and passes with it! Not sure offhand how hard that will be so if it's too hard it's probably ok to skip.
  • Similarly if it's not too hard you could add another unit test case with a schema that looks more like the hasura one. But I'm not sure how interesting that would be, maybe there's no need since existing tests are hitting this case.

@kevinmichaelchen
Copy link
Contributor Author

kevinmichaelchen commented May 4, 2023

a schema that looks more like the hasura one

Here's what I'm thinking for that:

Click me
##################
# Hasura.graphql #
##################
query GetPokemon($where: getPokemonBoolExp!) {
  getPokemon(where: $where) {
    level
  }
}

##################
# schema.graphql #
##################
type Query {
  getPokemon(where: getPokemonBoolExp): [Pokemon!]!
}

input getPokemonBoolExp {
  _and: [getPokemonBoolExp!]
  _not: getPokemonBoolExp
  _or: [getPokemonBoolExp!]
  level: IntComparisonExp
}

input IntComparisonExp {
  _eq: Int
  _gt: Int
  _gte: Int
  _in: [Int!]
  _isNull: Boolean
  _lt: Int
  _lte: Int
  _neq: Int
  _nin: [Int!]
}

@kevinmichaelchen
Copy link
Contributor Author

kevinmichaelchen commented May 4, 2023

OK, I managed to get snapshot generation working with

UPDATE_SNAPSHOTS=1 go test ./...

The challenge I'm now facing — and maybe this is not relevant to the original ticket — is to get omitempty tags on the fields inside IntComparisonExp

@benjaminjkraft
Copy link
Collaborator

Great, thanks! I think IntComparisonExp is another limitation, being discussed in #260 (there are a few ways around but none quite convenient for these hasura schemas). Anyway it's good to have the test; I think this weekend I'm going to try to understand what "make genqlient and hasura not fight so much" might mean more generally.

@benjaminjkraft benjaminjkraft merged commit 15f507b into Khan:main May 5, 2023
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.

2 participants