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

gqlgen v0.17.42 breaks / incompatible with gqlgenc vv0.16.0 #2874

Closed
matoszz opened this issue Dec 30, 2023 · 17 comments
Closed

gqlgen v0.17.42 breaks / incompatible with gqlgenc vv0.16.0 #2874

matoszz opened this issue Dec 30, 2023 · 17 comments

Comments

@matoszz
Copy link

matoszz commented Dec 30, 2023

What happened?

When pulling the update for gqlgen v0.17.42, there was an introduction of the creation of empty Query and Mutation structs which now conflict with the gqlgenc generated client that contain the same structs; an example diff I'm seeing when pulling in the new version can be seen here

What did you expect?

The underlying client generated models shouldn't contain empty Mutation and Query structs

Minimal graphql.schema and models to reproduce

I believe you can reproduce this with any schema, but specifically with the gqlgenc client generation enabled in conjunction with gqlgen. I've forked my underlying repo and generated the diff created by gqlgen / gqlgenc here

versions

  • go run github.com/99designs/gqlgen version v0.17.42?
  • go version 1.21.5?
@ghjm
Copy link
Contributor

ghjm commented Jan 2, 2024

This issue is affecting me as well.

@udhaykumarB
Copy link

same issue here

ghjm added a commit to ghjm/gqlgen that referenced this issue Jan 9, 2024
ghjm added a commit to ghjm/gqlgen that referenced this issue Jan 9, 2024
@skid-rock
Copy link

Same problem. Need to do something

@ghjm
Copy link
Contributor

ghjm commented Jan 12, 2024

If my PR #2878 is merged (and is included in a release, etc), you will be able to specify a new configuration option omit_root_models: true that will fix this.

@matoszz
Copy link
Author

matoszz commented Feb 5, 2024

@ghjm I'm testing gqlgen @ v0.17.43 (with #2878) + omit_root_models: true and gqlgenc @ v0.18.0 and it doesn't seem as though this flag (regardless of it's settings) is getting picked up. I attempted both true/false and noticed that there was no change output when running gqlgen directly (good) but when running gqlgenc it still outputs the base models regardless of the settings I have within gqlgen.yml - any advice? you see this working in-practice yet?

@ghjm
Copy link
Contributor

ghjm commented Feb 5, 2024

The client generator has always generated these base models. If you want gqlgenc not to output them, that would require a change in https://github.com/Yamashou/gqlgenc, not here. This PR just (optionally) prevents gqlgen from generating them, so that it doesn't conflict with gqlgenc.

@ghjm
Copy link
Contributor

ghjm commented Feb 5, 2024

Also, now that the PR has been merged, this issue can be closed. Cc @StevenACoffman

@matoszz
Copy link
Author

matoszz commented Feb 6, 2024

@ghjm shouldn't the change of the bool option in the gqlgen.yml actually produce a change in the output when generating? I guess I would have expected when uncommenting out that option in the configuration and running the generate commands that i'd see a diff in output with the option on / off but there's no file changes when doing so.

I originally reported this issue when the version of gqlgen I was trying to pull in started behaving in this way, but it seems as though it's always been erroneously generated by gqlgenc all along (I can bump gqlgenc version and not change gqlgen, generates fine; if i bump the gqlgen version + gqlgenc i get the empty structs)

@ghjm
Copy link
Contributor

ghjm commented Feb 6, 2024

You must be generating different packages for the client and the server. I was trying to avoid this, because I also use the generated structs for internal data handling, and I didn't want to have two different type systems for client-side and server-side representations of identical objects. So for me it is a problem that gqlgen started generating the empty Query and Mutation structs, because they conflict with the same-named structs generated by gqlgenc.

Whatever you're trying to do, it's not the same as what I was trying to do. This PR does solve my problem and I'm now able to upgrade to latest-version gqlgen without problems, as long as I set the configuration flag.

@ghjm
Copy link
Contributor

ghjm commented Feb 6, 2024

And maybe this issue shouldn't be closed since it is apparently not solved for @matoszz, who opened the issue.

@matoszz
Copy link
Author

matoszz commented Feb 6, 2024

@ghjm interesting, appreciate the response / feedback - I may be inadvertently generating different packages for the client and server as your description seems like what i'm trying to accomplish as I also use the generated structs for internal data handling. Would you mind sharing your gqlgen + gqlgenc configuration(s)? It'd be helpful for me to see how you're managing these as a single package in practice.

In my gqlgen.yml I have:

schema:
  - schema/*.graphql

exec:
  filename: internal/graphapi/gen_server.go
  package: graphapi

model:
  filename: internal/graphapi/gen_models.go
  package: graphapi

resolver:
  layout: follow-schema
  dir: internal/graphapi
  package: graphapi
  filename_template: "{name}.resolvers.go"

omit_gqlgen_version_in_file_notice: true

autobind:
 - "github.com/datumforge/datum/internal/graphapi"
 - "github.com/datumforge/datum/internal/ent/generated"

and gqlgenc.yml:

schema: ["schema.graphql" ]
query: ["query/*.graphql"]
model:
  package: datumclient
  filename: ./internal/datumclient/models.go
client:
  package: datumclient
  filename: ./internal/datumclient/graphclient.go
generate:
  clientV2: true
  clientInterfaceName: "DatumClient"

is it as simple as making the package names the same and aligning the model file names?

@Yamashou
Copy link

Yamashou commented Feb 6, 2024

A new version has been released to allow Query and Mutation to not be generated

generate:
  clientV2: true
  clientInterfaceName: "GithubGraphQLClient"
  query: false
  mutation: false

https://github.com/Yamashou/gqlgenc/releases/tag/v0.18.0

Please let me know if this release does not solve the problem.

@ghjm
Copy link
Contributor

ghjm commented Feb 6, 2024

@matoszz I followed these instructions from @Yamashou: Yamashou/gqlgenc#111. I don't use the gqlgenc CLI, and therefore, I don't use a gqlgenc.conf - instead I use Go code to run a pass of gqlgen that adds gqlgenc as a plugin. You can see an example of this here: https://github.com/ghjm/connectopus/tree/main/pkg/cpctl.

@matoszz
Copy link
Author

matoszz commented Feb 6, 2024

@Yamashou we updated gqlgenc to v.18.0 and tested both of those configuration parameters under generate (with gqlgen v0.17.43), and I believe this is what we needed - ref #495.

Really appreciate the assistance and responsiveness - thank you @ghjm @Yamashou 🙇 ❤️

@Yamashou
Copy link

@matoszz @ghjm

New version adds autobind functionality to gqlgenc. It is only for models, but if it helps I would be happy.

https://github.com/Yamashou/gqlgenc/releases/tag/v0.19.1

@onkarbanerjee
Copy link

@matoszz @ghjm

New version adds autobind functionality to gqlgenc. It is only for models, but if it helps I would be happy.

https://github.com/Yamashou/gqlgenc/releases/tag/v0.19.1

@Yamashou but this version still generates the empty structs in the model.

@Yamashou
Copy link

@onkarbanerjee
Please raise an issue on gqlgenc.

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

No branches or pull requests

7 participants