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

How to insert an object using mutation #37

Open
cedricve opened this issue Mar 13, 2019 · 1 comment
Open

How to insert an object using mutation #37

cedricve opened this issue Mar 13, 2019 · 1 comment
Labels
question WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@cedricve
Copy link

Hello,

Thank you for this amazing library, I'm trying to insert an object by executing an insert mutation.

So what I have is a simple table called events, with two properties id, event. So what I try to do is create an object with these two properties and insert it. However I'm not sure how to do it? Can someone have a quick look?

		listEvents := []*Events{}
		listEvents = append(listEvents, &Events{
			Event:     graphql.String("test event"),
		})

		var mutation struct {
			CreateEvents struct {
				Event string
			} `graphql:"CreateEvents(events:$events)"`
		}
		variables := map[string]interface{}{
			"event": listEvents,
		}

		if err := client.Mutate(context.Background(),&mutation, variables); err != nil {
			fmt.Println(err)
		}

The error I get is this..

non-200 OK status code: 400 Bad Request body: "{\"errors\":[{\"extensions\":{\"path\":\"$\",\"code\":\"validation-failed\"},\"message\":\"variables can only be defined on input types(enums, scC02XL1E5JHD3:graphC02XL1E5JHD3:grC02XL1C02XL1C02XL1E5JHD3C02XL1E5JC02C02XL1C02C02XL1E5JC02XL1E5JHD3:grC02XL1E5JHD3:grC02XL1C02C02XL1E5JHD3:grC02XL1C02XL1C02XL1E5JHD3C02XL1E5JHD3C02C02XL1E5JHD3C02
@dmitshur dmitshur added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 16, 2019
@dmitshur
Copy link
Member

dmitshur commented Mar 16, 2019

What GraphQL server are you using? Can we reproduce this error somehow?

It looks like the GraphQL server is returning an error "variables can only be defined on input types". Googling that error message gets me here: https://github.com/hasura/graphql-engine/blob/master/server/src-lib/Hasura/GraphQL/Validate.hs#L95. Is that the GraphQL server you're using? Perhaps you can try to ask there under which conditions that error is expected and to clarify the error message.

From what I see so far, the GraphQL client is working as intended. At least I'm not seeing a problem.

grihabor pushed a commit to grihabor/graphql that referenced this issue Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Development

No branches or pull requests

2 participants