fix: Fix path to GraphQL API when using GitHub Enterprise (#580)

The API path should be <ghe_host>/api/graphql, but
it is defaulting to <ghe_host>/api/v3/graphql.
This commit is contained in:
Morgan Delagrange
2018-06-27 19:11:34 -05:00
committed by Brandon Keepers
parent 43ea6ce815
commit 73ac539f45
3 changed files with 26 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ export function addGraphQL (client: GitHubAPI) {
async function graphql (client: GitHubAPI, query: string, variables: Variables, headers: Headers = {}) {
const res = await client.request({
baseUrl: process.env.GHE_HOST && `https://${process.env.GHE_HOST}/api`,
headers: {
'accept': 'application/json',
'content-type': 'application/json',

View File

@@ -29,6 +29,7 @@ export interface Options extends Octokit.Options {
}
export interface RequestOptions {
baseUrl?: string
method: string
url: string
headers: any

View File

@@ -76,4 +76,28 @@ describe('github/graphql', () => {
await expect(github.query(query)).rejects.toThrow('Unexpected end of document')
})
})
describe('ghe support', () => {
const query = 'query { viewer { login } }'
let data
beforeEach(() => {
process.env.GHE_HOST = 'notreallygithub.com'
})
afterEach(() => {
delete process.env.GHE_HOST
})
test('makes a graphql query', async () => {
data = { viewer: { login: 'bkeepers' } }
nock('https://notreallygithub.com', {
reqheaders: { 'content-type': 'application/json' }
}).post('/api/graphql', {query})
.reply(200, { data })
expect(await github.query(query)).toEqual(data)
})
})
})