graphql-go / graphql

An implementation of GraphQL for Go / Golang
MIT License
9.86k stars 838 forks source link

On mutation, should be added binding variables dynamically using placeholder #623

Open ghost opened 2 years ago

ghost commented 2 years ago

In the apollo documentation, you would have mutation:

      // Query
      mutation: gql`mutation ($label: String!) {
        addTag(label: $label) {
          id
          label
        }
      }`,
      // Parameters
      variables: {
        label: newTag,
      },

I really like the library but it is missing the critical thing which is you having to bind fields in graphql which is a real problem if we work with entities that have many fields.

Look at this example from the docs:

curl \-X POST \-H "Content-Type: application/json" \--data '{ "query": "mutation { createTodo(text:\"My New todo\") { id text done } }" }' \http://localhost:8080/graphql

I prefer my graphql calls to be POST calls, and to bind text inside the mutation, instead of just having in the payload body just like this:

{
"query": "mutation{ createTODO(input: $input) {id text done } }", 
"variables": { "input": { "text":"My New todo" }}
}

Apollo for example would be creating a similar request to this one I proposed.

This is an amazing library if you ask me and I would really like this feature to ease my client side development

bhoriuchi commented 2 years ago

not sure I understand the issue. This specific package does not provide an http server and you can provide variables to the Do method https://pkg.go.dev/github.com/graphql-go/graphql#Do using the VariableValues field in the Params object https://pkg.go.dev/github.com/graphql-go/graphql#Params

There is a link to a handler project that will serve your endpoint over http https://github.com/graphql-go/handler and i also maintain one here https://github.com/bhoriuchi/graphql-go-tools/tree/master/server