Skip to content

Commit 9366cb2

Browse files
committed
stabilize documents
1 parent 951ec25 commit 9366cb2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

plugin/src/gatsby-node.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { Kind } from 'gatsby/graphql';
55
import type { TypegenReporter } from './internal/reporter';
66
import { validateConfig } from './internal/config';
77
import { typegenMachine } from './internal/machine';
8+
import { sortDefinitions } from './internal/utils';
9+
810
import { makeEmitSchemaService } from './services/emitSchema';
911
import { makeEmitPluginDocumentService } from './services/emitPluginDocument';
1012
import { makeAutofixService } from './services/autofix';
@@ -150,6 +152,7 @@ export const onPreBootstrap: GatsbyNode['onPreBootstrap'] = ({
150152
codegen: context => codegen({
151153
schema: context.schema!,
152154
documents: [...context.trackedDefinitions?.values() || []]
155+
.sort(sortDefinitions)
153156
.map(definitionMeta => ({
154157
document: {
155158
kind: Kind.DOCUMENT,

plugin/src/internal/utils.ts

+12
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,15 @@ export function filterPluginSchema(schema: GraphQLSchema): GraphQLSchema {
191191
export function stabilizeSchema(schema: GraphQLSchema): GraphQLSchema {
192192
return lexicographicSortSchema(filterDevOnlySchema(schema));
193193
}
194+
195+
export function sortDefinitions(a: IDefinitionMeta, b: IDefinitionMeta): number {
196+
const aKey = a.name;
197+
const bKey = b.name;
198+
if (aKey < bKey) {
199+
return -1;
200+
}
201+
if (aKey > bKey) {
202+
return 1;
203+
}
204+
return 0;
205+
}

0 commit comments

Comments
 (0)