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

Empty but Duplicate Struct and Mutation in model file conflicting with client file. #199

Closed
brthode opened this issue Feb 8, 2024 · 10 comments

Comments

@brthode
Copy link

brthode commented Feb 8, 2024

gqlgenc Versions: v0.16.0 & v0.18.1
Schema Source: Remote Server
Command
cd ${GODIR}/testutils/portalapi_gqlclient && go run github.com/Yamashou/gqlgenc@latest generate

gqlgen Version: v0.17.43

I needed to add some additional queries to my GraphQL client so I included them in my query file and then regenerated my client. After doing so I am seeing an empty Query and Mutation struct in my model file. (external_api_models_gen.go)

type Query struct {
}

type Mutation struct {
}

These conflict with the populated struct's in my client. (external-gql-client.go)

Partial .gqlgenc.yml config

model:
  package: portalapi_gqlclient
  filename: ./external_api_models_gen.go
client:
  package: portalapi_gqlclient
  filename: ./external-gql-client.go
...
generate:
  clientV2: true
  clientInterfaceName: "XXXXXXGQLClient"

I tried upgrading from v0.16.0 to v0.18.1 but am observing the same behavior for both versions. Given the change in behavior prior to the version change, I believe this was being exposed by a change in our GQL schema, but the number of changes is so numerous as to make tracking it down difficult.

@skid-rock
Copy link

skid-rock commented Feb 13, 2024

Same problem. It would be nice if someone added settings for gqlgen, namely the omit_root_models setting

@skid-rock
Copy link

It seems I found a solution after digging into the code!
In v0.18.0 "Allow Query and Mutation type generation to be skipped"
see example https://github.com/Yamashou/gqlgenc/blob/master/example/github/.gqlgenc.yml

@ethomson1
Copy link

I am also having this problem. For me it started occurring when I tried to upgrade from 0.18.0 to 0.18.1.
I also noticed the example/github/gen/models_gen.go file in the diff has an empty Query and Mutation added to it.
v0.18.0...v0.18.1

I'm a little confused because the only other changes in this PR are updates to dependencies, so I don't know why these extra structs would be added to the generated code.

@Yamashou
Copy link
Owner

@ethomson1 @brthode
Will it still happen with the current updates?
https://github.com/Yamashou/gqlgenc/releases/tag/v0.19.1

@Yamashou
Copy link
Owner

Incidentally, the following settings are used to avoid generating Query and Mutation.

https://github.com/Yamashou/gqlgenc/blob/master/example/github/.gqlgenc.yml

@Yamashou
Copy link
Owner

@ethomson1
In v0.18.1 we have updated gqlgen.
gqlgen now generates Query and Mutation with this update.

@ethomson1
Copy link

@Yamashou I noticed that setting to avoid generating Query and Mutation. When I added it to my gqlgenc.yml, it got rid of the Query and Mutation definitions in my client.go, while the empty ones in models_gen.go were still generated. I was unsure if that's what is expected to happen when specifying those options. If that's expected, then I will re-add those settings so that I can complete my upgrade. Thanks!

@Yamashou
Copy link
Owner

That is the result of gqlgen's attempt to generate So, we recommend that you look for a way to prevent gqlgen from generating them

@ethomson1
Copy link

Okay, I see that there was an omit_root_models setting added in 99designs/gqlgen#2878.
Is there a way to expose this as an option in the gqlgenc file, so that we can prevent the empty root models from being generated?

@Yamashou
Copy link
Owner

@ethomson1
There is no way to do that; model generation uses gqlgen functionality, so gqlgen must provide the functionality.

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

4 participants