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

Unused Variable in generated.go #3348

Open
herzadinata opened this issue Oct 29, 2024 · 1 comment
Open

Unused Variable in generated.go #3348

herzadinata opened this issue Oct 29, 2024 · 1 comment

Comments

@herzadinata
Copy link

herzadinata commented Oct 29, 2024

What happened?

Afer running gqlgen generate

In VSCode using gopls, I got this warning that display

unused parameter: sel

Screenshot 2024-10-29 at 08 58 42

That is caused by sel param not used

// generated.go

...
func (ec *executionContext) marshalNBoolean2bool(
	ctx context.Context,
	sel ast.SelectionSet, // <= this part
	v bool,
) graphql.Marshaler {
	res := graphql.MarshalBoolean(v)
	if res == graphql.Null {
		if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
			ec.Errorf(ctx, "the requested element is null which the schema does not allow")
		}
	}
	return res
}
...

What did you expect?

I need the VSCode warning to dissappear, it's annoying and messup development experience.
The variable should be used or removed, but I can't change that because it is an auto generated file.
But I can't exclude that from gopls either. I have tried. To elaborate, I opened a question about it on StackOverflow:
https://stackoverflow.com/questions/79135399/exclude-directory-or-file-in-gopls

Minimal graphql.schema and models to reproduce

# GraphQL schema example
#
# https://gqlgen.com/getting-started/

type Query {
  character(id: ID!): Character
  pogues: [Character]!
  kooks: [Character]!
}

type Mutation {
  upsertCharacter(input: CharacterInput!): Character!
}

type Character {
  id: ID!
  name: String!
}

input CharacterInput {
  name: String!
  id: String
}

versions

  • gqlgen version: v0.17.55
  • go version go1.23.2 darwin/arm64
@StevenACoffman
Copy link
Collaborator

StevenACoffman commented Nov 7, 2024

PRs welcome!

Check out

func (ec *executionContext) {{ . }}(ctx context.Context, sel ast.SelectionSet, v {{ $type.GO | ref }}) graphql.Marshaler {

And find an appropriate condition that will allow us to choose to select _ instead of sel in that template.

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

2 participants