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

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

Open
xmlking opened this issue Jun 22, 2023 · 1 comment
Open

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

xmlking opened this issue Jun 22, 2023 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@xmlking
Copy link

xmlking commented Jun 22, 2023

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
@xmlking xmlking added the bug Something isn't working label Jun 22, 2023
benjaminjkraft added a commit that referenced this issue Aug 1, 2023
This PR makes [THIS ISSUE](#279)
a lot less likely to occur.
The local name "data" in generated functions was colliding with
arguments called "data".

Note that no explicit name collision check was added, but "data" inside
the function was just renamed to "data_" to make it less likely to
collide with arguments.

---------

Co-authored-by: Ben Kraft <[email protected]>
@benjaminjkraft
Copy link
Collaborator

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

@benjaminjkraft benjaminjkraft added this to the v1.0 milestone Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants