Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Send a simple query

```js
const graphql = require('@octokit/graphql')
const { data } = await graphql(`{
const { repository } = await graphql(`{
repository(owner:"octokit", name:"graphql.js") {
issues(last:3) {
edges {
Expand All @@ -34,7 +34,7 @@ const { data } = await graphql(`{

```js
const graphql = require('@octokit/graphql')
const { data } = await graphql(`query lastIssues($owner: String!, $repo: String!, $num: Int = 3) {
const { lastIssues } = await graphql(`query lastIssues($owner: String!, $repo: String!, $num: Int = 3) {
repository(owner:$owner, name:$repo) {
issues(last:$num) {
edges {
Expand Down Expand Up @@ -62,7 +62,7 @@ const graphql = require('@octokit/graphql').defaults({
authorization: `token secret123`
}
})
const { data } = await graphql(`{
const { repository } = await graphql(`{
repository(owner:"octokit", name:"graphql.js") {
issues(last:3) {
edges {
Expand All @@ -79,7 +79,7 @@ Pass query together with headers and variables

```js
const graphql = require('@octokit/graphql')
const { data } = await graphql({
const { lastIssues } = await graphql({
query: `query lastIssues($owner: String!, $repo: String!, $num: Int = 3) {
repository(owner:$owner, name:$repo) {
issues(last:$num) {
Expand Down Expand Up @@ -108,7 +108,7 @@ const graphql = require('@octokit/graphql').defaults({
authorization: `token secret123`
}
})
const { data } = await graphql(`{
const { repository } = await graphql(`{
repository(owner:"acme-project", name:"acme-repo") {
issues(last:3) {
edges {
Expand Down Expand Up @@ -138,7 +138,7 @@ const query = `{
}`

try {
const { data } = await graphql(query)
const result = await graphql(query)
} catch (error) {
// server responds with
// {
Expand Down
1 change: 1 addition & 0 deletions lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = class GraphqlError extends Error {
super(message)

Object.assign(this, response.data)
this.name = 'GraphqlError'
this.request = request

// Maintains proper stack trace (only available on V8)
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function graphql (request, query, options) {
return request(requestOptions)
.then(response => {
if (response.data.data) {
return response.data
return response.data.data
}

throw new GraphqlError(requestOptions, response)
Expand Down
8 changes: 4 additions & 4 deletions test/defaults-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ describe('graphql.defaults()', () => {
}
}
}`)
.then(response => {
expect(response.data).to.deep.equal(mockData)
.then(result => {
expect(result).to.deep.equal(mockData)
})
})

Expand Down Expand Up @@ -115,8 +115,8 @@ describe('graphql.defaults()', () => {
}
}
}`)
.then(response => {
expect(response.data).to.deep.equal(mockData)
.then(result => {
expect(result).to.deep.equal(mockData)
})
})
})
2 changes: 1 addition & 1 deletion test/error-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('errors', () => {
}
})

.then(response => {
.then(result => {
throw new Error('Should not resolve')
})

Expand Down
4 changes: 2 additions & 2 deletions test/graphql-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ describe('graphql()', () => {
}
})

.then(response => {
expect(response.data).to.deep.equal(mockData)
.then(result => {
expect(result).to.deep.equal(mockData)
})
})

Expand Down