|
1 | 1 | import * as fs from 'node:fs';
|
| 2 | +import { createHash } from 'crypto'; |
2 | 3 | import { printSchema } from 'graphql/src/utilities/printSchema.js';
|
3 | 4 | import { schemas, testCases } from 'graphql/src/validation/__tests__/harness.js';
|
4 | 5 |
|
@@ -36,10 +37,31 @@ import 'graphql/src/validation/__tests__/VariablesAreInputTypesRule-test.js';
|
36 | 37 | // require('graphql/src/validation/__tests__/VariablesDefaultValueAllowed-test');
|
37 | 38 | import 'graphql/src/validation/__tests__/VariablesInAllowedPositionRule-test.js';
|
38 | 39 |
|
39 |
| -let output = JSON.stringify({ |
40 |
| - schemas: schemas().map(s => printSchema(s)), |
41 |
| - tests: testCases(), |
42 |
| -}, null, 2) |
| 40 | +// Schema index in the source array can be unstable, as its dependent on the order they are used in the registered test |
| 41 | +// files. The SHA256 of the schema will change if there are any changes to the content, but is a better reference than |
| 42 | +// the schema indexes all changing when a new schema is inserted. |
| 43 | +let s = schemas().map(s => { |
| 44 | + const sdl = printSchema(s) |
| 45 | + const id = createHash('sha256').update(sdl).digest('base64'); |
| 46 | + const v: { id: string; sdl: string; } = {id: id, sdl: sdl}; |
| 47 | + return v; |
| 48 | +}); |
| 49 | + |
| 50 | +const tests = testCases().map(c => { |
| 51 | + const schema = s[c.schema]; |
| 52 | + return { |
| 53 | + name: c.name, |
| 54 | + rule: c.rule, |
| 55 | + schema: schema.id, |
| 56 | + query: c.query, |
| 57 | + errors: c.errors, |
| 58 | + } |
| 59 | +}); |
| 60 | + |
| 61 | +// Order based on the schema string to provide semi-stable ordering |
| 62 | +s = s.sort((a, b) => a.sdl.localeCompare(b.sdl)); |
| 63 | + |
| 64 | +let output = JSON.stringify({schemas: s, tests: tests}, null, 2) |
43 | 65 | output = output.replace(/ Did you mean to use an inline fragment on [^?]*\?/g, '');
|
44 | 66 | // Ignore suggested types in errors, which graphql-go does not currently produce.
|
45 | 67 | output = output.replace(/ Did you mean \\"[A-Z].*\"\?/g, '');
|
|
0 commit comments