Khan / genqlient

a truly type-safe Go GraphQL client
MIT License
1.03k stars 99 forks source link

codegen error: 'data' redeclared in this block #279

Open xmlking opened 1 year ago

xmlking commented 1 year ago

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

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

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
benjaminjkraft commented 11 months ago

Common cases of this are fixed in #291. Leaving this open for a general fix.