Skip to content

Commit

Permalink
stabilize documents
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Jun 12, 2022
1 parent 951ec25 commit 9366cb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugin/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Kind } from 'gatsby/graphql';
import type { TypegenReporter } from './internal/reporter';
import { validateConfig } from './internal/config';
import { typegenMachine } from './internal/machine';
import { sortDefinitions } from './internal/utils';

import { makeEmitSchemaService } from './services/emitSchema';
import { makeEmitPluginDocumentService } from './services/emitPluginDocument';
import { makeAutofixService } from './services/autofix';
Expand Down Expand Up @@ -150,6 +152,7 @@ export const onPreBootstrap: GatsbyNode['onPreBootstrap'] = ({
codegen: context => codegen({
schema: context.schema!,
documents: [...context.trackedDefinitions?.values() || []]
.sort(sortDefinitions)
.map(definitionMeta => ({
document: {
kind: Kind.DOCUMENT,
Expand Down
12 changes: 12 additions & 0 deletions plugin/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,15 @@ export function filterPluginSchema(schema: GraphQLSchema): GraphQLSchema {
export function stabilizeSchema(schema: GraphQLSchema): GraphQLSchema {
return lexicographicSortSchema(filterDevOnlySchema(schema));
}

export function sortDefinitions(a: IDefinitionMeta, b: IDefinitionMeta): number {
const aKey = a.name;
const bKey = b.name;
if (aKey < bKey) {
return -1;
}
if (aKey > bKey) {
return 1;
}
return 0;
}

0 comments on commit 9366cb2

Please sign in to comment.