Khan / Khan/genqlient

codegen error: 'data' redeclared in this block

Open
#279 1 comment 1 reaction 0 assignees View on GitHub
bug
Dominant language
Go
Stars
1.3k
Forks
143
Avg merge
4h 50m
Merged PRs (30d)
1

Description

I am using **Hasura** scheme. the generated code is using a redeclared variable which is causing `'data' redeclared in this block` error.

I have to mutually edit `UpsertDeviceResponse` from `data` to `data2`
is there any workaround?

### manual fix
```go
func UpsertDevice(
ctx context.Context,
client graphql.Client,
data Devices_insert_input,
) (*UpsertDeviceResponse, error) {
req := &graphql.Request{
OpName: "UpsertDevice",
Query: UpsertDevice_Operation,
Variables: &__UpsertDeviceInput{
Data: data,
},
}
var err error

var data2 UpsertDeviceResponse
resp := &graphql.Response{Data: &data}

err = client.MakeRequest(
ctx,
req,
resp,
)

return &data2, err
}
```

### query
```gql
mutation UpsertDevice($data: devices_insert_input!) {
insert_devices_one(object: $data, on_conflict: {update_columns: [ip, description, tags, annotations], constraint: devices_display_name_organization_key, where: {deletedAt: {_is_null: true}}}) {
annotations
ip
id
displayName
...
}
}
```
'data' redeclared in this block

image

image

Contributor guide

Open the contributing guide

Research direction

Start with the generated UpsertDevice function and the Hasura mutation shown in the issue; trace how the query variable named data becomes the response value. Reproduce generation with this mutation and verify that the generated Go compiles without a redeclaration while preserving the request and response behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, graphql
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.