khaosdoctor / gotql

GraphQL query utility for serverside apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEATURE] Insert multiple values from mutation

philipp-tailor opened this issue · comments

Right now, it doesn't seem possible to insert multiple values from one mutation.

Example graphQL query:

mutation insertMultipleThings($things: [things_insert_input!]!) {
	insert_things(objects: $things) {
		affected_rows
	}
}

The equivalent I tried with gotql was:

const things = [{name: 'thing1'}, {name: 'thing2'}]
const mutation = {
  operation: {
    name: 'insert_things',
    args: {
      objects: things,
    },
    fields: ['affected_rows'],
  },
}

gotQl.mutation(graphQLEndpoint, mutation)

I also attempted the less intuitive:

const things = [{name: 'thing1'}, {name: 'thing2'}]
const mutation = {
  operation: {
    name: 'insert_things',
    args: {
      objects: {
	value: things,
	escape: false,
      },
    },
    fields: ['affected_rows'],
  },
}

gotQl.mutation(graphQLEndpoint, mutation)

In the end I had to go with the horrifying:

const things = JSON.stringify([{name: 'thing1'}, {name: 'thing2'}]).split('"name"').join('name')
const mutation = {
  operation: {
    name: 'insert_things',
    args: {
      objects: {
	value: things,
	escape: false,
      },
    },
    fields: ['affected_rows'],
  },
}

gotQl.mutation(graphQLEndpoint, mutation)

Given that operation.args.objects has the plural already in the name and it's a valid query to pass an array, I'd expect objects to be allowed being passed an array (my first gotql attempt).

Hey! Thanks for the PR!

Can you please provide a graphQL query with values, so I can take a look on what might be going wrong? And also your final parsed query using GotQL?

Closing due to lack of response