@@ -2,67 +2,14 @@ import {
22 printSchema ,
33 findBreakingChanges ,
44 findDangerousChanges ,
5- GraphQLSchema ,
6- buildClientSchema ,
75 DangerousChange ,
8- BreakingChange ,
9- introspectionFromSchema ,
10- getIntrospectionQuery
6+ BreakingChange
117} from 'graphql' ;
128import { lexicographicSortSchema } from 'graphql/utilities' ;
13- import fetch from 'node-fetch' ;
149import disparity from 'disparity' ;
1510import { loadSchema } from 'graphql-toolkit' ;
1611
17- export interface Headers {
18- [ key : string ] : string ;
19- }
20-
21- async function fetchRemoteSchema (
22- endpoint : string ,
23- headers ?: Headers
24- ) : Promise < GraphQLSchema > {
25- const introspectionQuery = getIntrospectionQuery ( { descriptions : false } ) ;
26- const res = await fetch ( endpoint , {
27- method : 'POST' ,
28- headers : {
29- 'content-type' : 'application/json' ,
30- ...headers
31- } ,
32- body : JSON . stringify ( { query : introspectionQuery } )
33- } ) ;
34-
35- if ( ! res . ok ) {
36- throw new Error ( `${ res . status } - ${ res . statusText } (${ endpoint } )` ) ;
37- }
38-
39- const responseBody = await res . json ( ) ;
40-
41- if ( ! responseBody || ! responseBody . data || ! responseBody . data . __schema ) {
42- throw new Error ( `Invalid response from GraphQL endpoint: ${ endpoint } ` ) ;
43- }
44-
45- return buildClientSchema ( responseBody . data ) ;
46- }
47-
48- async function readLocalSchema ( schemaPath : string ) : Promise < GraphQLSchema > {
49- const schema = await loadSchema ( schemaPath ) ;
50- const introspection = introspectionFromSchema ( schema , {
51- descriptions : false
52- } ) ;
53- return buildClientSchema ( introspection ) ;
54- }
55-
56- async function getSchema (
57- schemaLocation : string ,
58- options : { headers ?: Headers } = { }
59- ) : Promise < GraphQLSchema > {
60- if ( schemaLocation . match ( / ^ h t t p s ? / ) ) {
61- return fetchRemoteSchema ( schemaLocation , options . headers ) ;
62- } else {
63- return readLocalSchema ( schemaLocation ) ;
64- }
65- }
12+ export type Headers = Record < string , string > ;
6613
6714export interface DiffResponse {
6815 diff : string ;
@@ -100,8 +47,8 @@ export async function getDiff(
10047 }
10148 } ;
10249 let [ leftSchema , rightSchema ] = await Promise . all ( [
103- getSchema ( leftSchemaLocation , leftSchemaOptions ) ,
104- getSchema ( rightSchemaLocation , rightSchemaOptions )
50+ loadSchema ( leftSchemaLocation , leftSchemaOptions ) ,
51+ loadSchema ( rightSchemaLocation , rightSchemaOptions )
10552 ] ) ;
10653
10754 if ( ! leftSchema || ! rightSchema ) {
0 commit comments