|
| 1 | +/** |
| 2 | + * Script to dump the GraphQL schema to a file. |
| 3 | + * This was written during the transition to Pothos-generated schema, |
| 4 | + * for comparison with the hand-written schema. |
| 5 | + * |
| 6 | + * It is written as a test because the schema's imports are entangled |
| 7 | + * with the rest of the server code, and this allows us to mock out the dependencies. |
| 8 | + */ |
| 9 | +import { vi } from "vitest" |
| 10 | + |
| 11 | +vi.mock("ioredis", () => { |
| 12 | + const RedisMock = vi.fn() |
| 13 | + RedisMock.prototype.on = vi.fn() |
| 14 | + RedisMock.prototype.connect = vi.fn() |
| 15 | + return { default: RedisMock } |
| 16 | +}) |
| 17 | +vi.mock("../src/elasticsearch/elastic-client", () => ({ |
| 18 | + elasticClient: {}, |
| 19 | +})) |
| 20 | +vi.mock("../src/config", () => ({ |
| 21 | + default: { |
| 22 | + url: "http://localhost", |
| 23 | + auth: { jwt: { secret: "test-secret-for-schema-dump" } }, |
| 24 | + datalad: { uri: "http://localhost" }, |
| 25 | + mongo: { url: "mongodb://localhost", dbName: "test" }, |
| 26 | + redis: {}, |
| 27 | + }, |
| 28 | +})) |
| 29 | + |
| 30 | +import { writeFileSync } from "fs" |
| 31 | +import { dirname, join } from "path" |
| 32 | +import { fileURLToPath } from "url" |
| 33 | +import { lexicographicSortSchema, printSchema } from "graphql/index.js" |
| 34 | +import schema from "../src/graphql/schema" |
| 35 | + |
| 36 | +it("dumps Pothos schema to SDL", () => { |
| 37 | + const sdl = printSchema(lexicographicSortSchema(schema)) |
| 38 | + const dir = dirname(fileURLToPath(import.meta.url)) |
| 39 | + writeFileSync(join(dir, "..", "schema.graphql"), sdl + "\n") |
| 40 | +}) |
0 commit comments