|
1 | 1 | import * as pg from "pg"; |
2 | 2 | import { parse, buildASTSchema, GraphQLSchema } from "graphql"; |
3 | | -import { printSchema } from "graphql/utilities"; |
| 3 | +import { lexicographicSortSchema, printSchema } from "graphql/utilities"; |
4 | 4 |
|
5 | 5 | export async function withPgPool<T>( |
6 | 6 | cb: (pool: pg.Pool) => Promise<T> |
@@ -46,33 +46,5 @@ export function printSchemaOrdered(originalSchema: GraphQLSchema): string { |
46 | 46 | // Clone schema so we don't damage anything |
47 | 47 | const schema = buildASTSchema(parse(printSchema(originalSchema))); |
48 | 48 |
|
49 | | - const typeMap = schema.getTypeMap(); |
50 | | - Object.keys(typeMap).forEach((name) => { |
51 | | - const gqlType = typeMap[name]; |
52 | | - |
53 | | - // Object? |
54 | | - if ("getFields" in gqlType) { |
55 | | - const fields = gqlType.getFields(); |
56 | | - const keys = Object.keys(fields).sort(); |
57 | | - keys.forEach((key) => { |
58 | | - const value = fields[key]; |
59 | | - |
60 | | - // Move the key to the end of the object |
61 | | - delete fields[key]; |
62 | | - fields[key] = value; |
63 | | - |
64 | | - // Sort args |
65 | | - if ("args" in value) { |
66 | | - value.args.sort((a, b) => a.name.localeCompare(b.name)); |
67 | | - } |
68 | | - }); |
69 | | - } |
70 | | - |
71 | | - // Enum? |
72 | | - if ("getValues" in gqlType) { |
73 | | - gqlType.getValues().sort((a, b) => a.name.localeCompare(b.name)); |
74 | | - } |
75 | | - }); |
76 | | - |
77 | | - return printSchema(schema); |
| 49 | + return printSchema(lexicographicSortSchema(schema)); |
78 | 50 | } |
0 commit comments