|
| 1 | +import * as fs from 'node:fs'; |
| 2 | +import { createHash } from 'crypto'; |
| 3 | +import { printSchema } from 'graphql/src/utilities/printSchema.js'; |
| 4 | +import { schemas, testCases } from 'graphql/src/validation/__tests__/harness.js'; |
| 5 | + |
| 6 | +// TODO: Fix test failures. |
| 7 | +// require('graphql/src/validation/__tests__/ExecutableDefinitions-test'); |
| 8 | +import 'graphql/src/validation/__tests__/FieldsOnCorrectTypeRule-test.js'; |
| 9 | +import 'graphql/src/validation/__tests__/FragmentsOnCompositeTypesRule-test.js'; |
| 10 | +import 'graphql/src/validation/__tests__/KnownArgumentNamesRule-test.js'; |
| 11 | +import 'graphql/src/validation/__tests__/KnownDirectivesRule-test.js'; |
| 12 | +import 'graphql/src/validation/__tests__/KnownFragmentNamesRule-test.js'; |
| 13 | +import 'graphql/src/validation/__tests__/KnownTypeNamesRule-test.js'; |
| 14 | +import 'graphql/src/validation/__tests__/LoneAnonymousOperationRule-test.js'; |
| 15 | +import 'graphql/src/validation/__tests__/NoFragmentCyclesRule-test.js'; |
| 16 | +import 'graphql/src/validation/__tests__/NoUndefinedVariablesRule-test.js'; |
| 17 | +import 'graphql/src/validation/__tests__/NoUnusedFragmentsRule-test.js'; |
| 18 | +import 'graphql/src/validation/__tests__/NoUnusedVariablesRule-test.js'; |
| 19 | +import 'graphql/src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.js'; |
| 20 | +import 'graphql/src/validation/__tests__/PossibleFragmentSpreadsRule-test.js'; |
| 21 | +import 'graphql/src/validation/__tests__/ProvidedRequiredArgumentsRule-test.js'; |
| 22 | +import 'graphql/src/validation/__tests__/ScalarLeafsRule-test.js'; |
| 23 | +// TODO: Add support for subscriptions. |
| 24 | +// require('graphql/src/validation/__tests__/SingleFieldSubscriptions-test.js'); |
| 25 | +import 'graphql/src/validation/__tests__/UniqueArgumentNamesRule-test.js'; |
| 26 | +import 'graphql/src/validation/__tests__/UniqueDirectivesPerLocationRule-test.js'; |
| 27 | +import 'graphql/src/validation/__tests__/UniqueFragmentNamesRule-test.js'; |
| 28 | +import 'graphql/src/validation/__tests__/UniqueInputFieldNamesRule-test.js'; |
| 29 | +import 'graphql/src/validation/__tests__/UniqueOperationNamesRule-test.js'; |
| 30 | +import 'graphql/src/validation/__tests__/UniqueVariableNamesRule-test.js'; |
| 31 | +// TODO: Fix test failures. |
| 32 | +// require('graphql/src/validation/__tests__/ValuesofCorrectType-test'); |
| 33 | +import 'graphql/src/validation/__tests__/VariablesAreInputTypesRule-test.js'; |
| 34 | +// TODO: Fix test failures. |
| 35 | +// require('graphql/src/validation/__tests__/VariablesDefaultValueAllowed-test'); |
| 36 | +import 'graphql/src/validation/__tests__/VariablesInAllowedPositionRule-test.js'; |
| 37 | + |
| 38 | +// Schema index in the source array can be unstable, as its dependent on the order they are used in the registered test |
| 39 | +// files. The SHA256 of the schema will change if there are any changes to the content, but is a better reference than |
| 40 | +// the schema indexes all changing when a new schema is inserted. |
| 41 | +let s = schemas().map(s => { |
| 42 | + const sdl = printSchema(s) |
| 43 | + const id = createHash('sha256').update(sdl).digest('base64'); |
| 44 | + const v: { id: string; sdl: string; } = {id: id, sdl: sdl}; |
| 45 | + return v; |
| 46 | +}); |
| 47 | + |
| 48 | +const tests = testCases().map(c => { |
| 49 | + const schema = s[c.schema]; |
| 50 | + return { |
| 51 | + name: c.name, |
| 52 | + rule: c.rule, |
| 53 | + schema: schema.id, |
| 54 | + query: c.query, |
| 55 | + errors: c.errors, |
| 56 | + } |
| 57 | +}); |
| 58 | + |
| 59 | +// Order based on the schema string to provide semi-stable ordering |
| 60 | +s = s.sort((a, b) => a.sdl.localeCompare(b.sdl)); |
| 61 | + |
| 62 | +let output = JSON.stringify({schemas: s, tests: tests}, null, 2) |
| 63 | +output = output.replace(/ Did you mean to use an inline fragment on [^?]*\?/g, ''); |
| 64 | +// Ignore suggested types in errors, which graphql-go does not currently produce. |
| 65 | +output = output.replace(/ Did you mean \\"[A-Z].*\"\?/g, ''); |
| 66 | +fs.writeFileSync("tests.json", output); |
0 commit comments