Commit 873d6ecd authored by Vitali Tatarintev's avatar Vitali Tatarintev

Allow to pass block to graphql_mutation helper

Adds a syntactic sugar for the `graphql_mutation` method
which allows passing a block as a GraphQL query.

Example before:

```
graphql_mutation(:update_alert_status, variables.merge(input),
                 <<~QL
                   clientMutationId
                   errors
                   alert {
                     iid
                     status
                   }
                 QL
)
```

Example after:

```
graphql_mutation(:update_alert_status, variables.merge(input)) do
  <<~QL
     clientMutationId
     errors
     alert {
       iid
       status
     }
  QL
end
```
parent acca4e78
......@@ -77,10 +77,12 @@ module GraphqlHelpers
QUERY
end
def graphql_mutation(name, input, fields = nil)
def graphql_mutation(name, input, fields = nil, &block)
mutation_name = GraphqlHelpers.fieldnamerize(name)
input_variable_name = "$#{input_variable_name_for_mutation(name)}"
mutation_field = GitlabSchema.mutation.fields[mutation_name]
fields = yield if block_given?
fields ||= all_graphql_fields_for(mutation_field.type.to_graphql)
query = <<~MUTATION
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment