@@ -18,6 +18,8 @@ import { handler as uriHandler } from '../common/uri';
1818import { createHttpLink } from 'apollo-link-http' ;
1919import fetch from 'node-fetch' ;
2020import { ITelemetry } from '../common/telemetry' ;
21+ const defaultSchema = require ( './queries.gql' ) ;
22+ const enterpriseSchema = require ( './enterprise.gql' ) ;
2123
2224const TRY_AGAIN = 'Try again?' ;
2325const SIGNIN_COMMAND = 'Sign in' ;
@@ -29,6 +31,7 @@ const AUTH_INPUT_TOKEN_CMD = 'auth.inputTokenCallback';
2931export interface GitHub {
3032 octokit : Octokit ;
3133 graphql : ApolloClient < NormalizedCacheObject > | null ;
34+ schema : any | null ;
3235}
3336
3437export class CredentialStore implements vscode . Disposable {
@@ -218,8 +221,28 @@ export class CredentialStore implements vscode.Disposable {
218221 }
219222 } ) ;
220223
224+ // detect which schema to use, currently only supports github.com & enterprise
225+ let version = '' ;
226+ const resp = await octokit . request ( 'GET /' ) ;
227+ if ( 'x-github-enterprise-version' in resp . headers ) {
228+ version = resp . headers [ 'x-github-enterprise-version' ] ;
229+ }
230+ let schema ;
231+ if ( version === '' ) {
232+ // use default github.com schema
233+ schema = defaultSchema ;
234+ } else {
235+ schema = enterpriseSchema ;
236+ }
237+
238+ let graphQLBaseURL = baseUrl ;
239+ if ( graphQLBaseURL . endsWith ( '/api/v3' ) ) {
240+ // handles github enterprise
241+ graphQLBaseURL = baseUrl . replace ( '/v3' , '' ) ;
242+ }
243+
221244 const graphql = new ApolloClient ( {
222- link : link ( baseUrl , creds . token || '' ) ,
245+ link : link ( graphQLBaseURL , creds . token || '' ) ,
223246 cache : new InMemoryCache ,
224247 defaultOptions : {
225248 query : {
@@ -231,15 +254,15 @@ export class CredentialStore implements vscode.Disposable {
231254 let supportsGraphQL = true ;
232255 await graphql . query ( { query : gql `query { viewer { login } }` } )
233256 . then ( result => {
234- Logger . appendLine ( `${ baseUrl } : GraphQL support detected` ) ;
257+ Logger . appendLine ( `${ graphQLBaseURL } : GraphQL support detected` ) ;
235258
236259 /* __GDPR__
237260 "auth.graphql.supported" : {}
238261 */
239262 this . _telemetry . sendTelemetryEvent ( 'auth.graphql.supported' ) ;
240263 } )
241264 . catch ( err => {
242- Logger . appendLine ( `${ baseUrl } : GraphQL not supported (${ err . message } )` ) ;
265+ Logger . appendLine ( `${ graphQLBaseURL } : GraphQL not supported (${ err . message } )` ) ;
243266 /* __GDPR__
244267 "auth.graphql.unsupported" : {}
245268 */
@@ -250,6 +273,7 @@ export class CredentialStore implements vscode.Disposable {
250273 return {
251274 octokit,
252275 graphql : supportsGraphQL ? graphql : null ,
276+ schema : schema ,
253277 } ;
254278 }
255279
0 commit comments