Skip to content

Commit

Permalink
fix: don’t send empty variables object
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jan 8, 2019
1 parent 295da93 commit af96d49
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ const GraphqlError = require('./error')
const NON_VARIABLE_OPTIONS = ['method', 'baseUrl', 'url', 'headers', 'request', 'query']

function graphql (request, query, options) {
const requestOptions = {
variables: {}
}

if (typeof query === 'string') {
options = Object.assign({ query }, options)
} else {
options = query
}

Object.keys(options).forEach(key => {
const requestOptions = Object.keys(options).reduce((result, key) => {
if (NON_VARIABLE_OPTIONS.includes(key)) {
requestOptions[key] = options[key]
return
result[key] = options[key]
return result
}

if (!result.variables) {
result.variables = {}
}

requestOptions.variables[key] = options[key]
})
result.variables[key] = options[key]
return result
}, {})

return request(requestOptions)
.then(response => {
Expand Down

0 comments on commit af96d49

Please sign in to comment.