@@ -10,6 +10,7 @@ import {
1010 introspectionFromSchema ,
1111 getIntrospectionQuery
1212} from 'graphql' ;
13+ import { lexicographicSortSchema } from 'graphql/utilities' ;
1314import fs from 'fs' ;
1415import isGlob from 'is-glob' ;
1516import fetch from 'node-fetch' ;
@@ -63,7 +64,9 @@ function readLocalSchema(schemaPath: string): GraphQLSchema {
6364 }
6465
6566 const schema = buildSchema ( schemaString ) ;
66- const introspection = introspectionFromSchema ( schema , { descriptions : false } )
67+ const introspection = introspectionFromSchema ( schema , {
68+ descriptions : false
69+ } ) ;
6770 return buildClientSchema ( introspection ) ;
6871}
6972
@@ -93,6 +96,7 @@ export interface DiffOptions {
9396 headers ?: Headers ;
9497 } ;
9598 headers ?: Headers ;
99+ sortSchema ?: boolean ;
96100}
97101
98102export async function getDiff (
@@ -112,7 +116,7 @@ export async function getDiff(
112116 ...( options . rightSchema && options . rightSchema . headers )
113117 }
114118 } ;
115- const [ leftSchema , rightSchema ] = await Promise . all ( [
119+ let [ leftSchema , rightSchema ] = await Promise . all ( [
116120 getSchema ( leftSchemaLocation , leftSchemaOptions ) ,
117121 getSchema ( rightSchemaLocation , rightSchemaOptions )
118122 ] ) ;
@@ -121,6 +125,13 @@ export async function getDiff(
121125 throw new Error ( 'Schemas not defined' ) ;
122126 }
123127
128+ if ( options . sortSchema ) {
129+ [ leftSchema , rightSchema ] = [
130+ lexicographicSortSchema ( leftSchema ) ,
131+ lexicographicSortSchema ( rightSchema )
132+ ] ;
133+ }
134+
124135 const [ leftSchemaSDL , rightSchemaSDL ] = [
125136 printSchema ( leftSchema ) ,
126137 printSchema ( rightSchema )
0 commit comments