diff --git a/packages/graphql-config/package.json b/packages/graphql-config/package.json index ad9d3391..c69f6219 100644 --- a/packages/graphql-config/package.json +++ b/packages/graphql-config/package.json @@ -6,12 +6,12 @@ "description": "GraphQL configuration for fabrix", "exports": { ".": { - "types": "./dist/index.d.mts", - "default": "./dist/index.mjs" + "types": "./dist/index.d.ts", + "default": "./dist/index.js" }, "./schema": { - "types": "./dist/schema.d.mts", - "default": "./dist/schema.mjs" + "types": "./dist/schema.d.ts", + "default": "./dist/schema.js" } }, "files": [ @@ -25,6 +25,7 @@ "test": "vitest run" }, "dependencies": { + "@graphql-tools/merge": "^9.0.8", "graphql": "^16.9.0" }, "devDependencies": { @@ -36,7 +37,7 @@ "prettier": "^3.3.3", "tsup": "^8.1.0", "typescript": "^5.5.3", - "vite-plugin-graphql-loader": "^4.0.4", + "vite-plugin-string": "^1.2.3", "vitest": "^2.0.3" }, "prettier": "@fabrix-framework/prettier-config" diff --git a/packages/graphql-config/src/graphql.d.ts b/packages/graphql-config/src/graphql.d.ts index 50b008e1..dc2883a8 100644 --- a/packages/graphql-config/src/graphql.d.ts +++ b/packages/graphql-config/src/graphql.d.ts @@ -1,4 +1,4 @@ declare module "*.graphql" { - const Document: import("graphql").DocumentNode; + const Document: string; export default Document; } diff --git a/packages/graphql-config/src/schema.test.ts b/packages/graphql-config/src/schema.test.ts new file mode 100644 index 00000000..54e38750 --- /dev/null +++ b/packages/graphql-config/src/schema.test.ts @@ -0,0 +1,9 @@ +import { describe, it, expect } from "vitest"; +import { buildASTSchema } from "graphql"; +import { schemaDefinition } from "./schema"; + +describe.skip("schemaDefinition", () => { + it("should be buildable", () => { + expect(buildASTSchema(schemaDefinition)).not.toThrow(); + }); +}); diff --git a/packages/graphql-config/src/schema.ts b/packages/graphql-config/src/schema.ts index 40014ee4..f74c17bb 100644 --- a/packages/graphql-config/src/schema.ts +++ b/packages/graphql-config/src/schema.ts @@ -1,17 +1,18 @@ -import { DocumentNode, Kind } from "graphql"; +import { parse } from "graphql"; +import { mergeTypeDefs } from "@graphql-tools/merge"; import CommonSchema from "./schema/common.graphql"; import ViewDirectiveSchema from "./schema/view.graphql"; import FormDirectiveSchema from "./schema/form.graphql"; import ConstraintSchema from "./schema/constraint.graphql"; -const mergeDocumentNodes = (docs: DocumentNode[]) => ({ - kind: Kind.DOCUMENT, - definitions: docs.flatMap((doc) => doc.definitions), -}); +const parseStringSchemas = (rawDefinition: string[]) => + rawDefinition.map((def) => parse(def)); -export const schemaDefinition = mergeDocumentNodes([ - CommonSchema, - ViewDirectiveSchema, - FormDirectiveSchema, - ConstraintSchema, -]); +export const schemaDefinition = mergeTypeDefs( + parseStringSchemas([ + CommonSchema, + ViewDirectiveSchema, + FormDirectiveSchema, + ConstraintSchema, + ]), +); diff --git a/packages/graphql-config/vitest.config.ts b/packages/graphql-config/vitest.config.ts index 394fbe94..2711afaf 100644 --- a/packages/graphql-config/vitest.config.ts +++ b/packages/graphql-config/vitest.config.ts @@ -1,8 +1,14 @@ import { defineConfig } from "vitest/config"; -import graphqlLoader from "vite-plugin-graphql-loader"; +import stringPlugin from "vite-plugin-string"; export default defineConfig({ - plugins: [graphqlLoader()], + plugins: [ + // Load .graphql files as strings as production build with tsup also does + stringPlugin({ + include: "**/*.graphql", + compress: false, + }), + ], test: { include: ["src/**/*.test.ts"], }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 954886bf..621d579b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -275,6 +275,9 @@ importers: packages/graphql-config: dependencies: + '@graphql-tools/merge': + specifier: ^9.0.8 + version: 9.0.8(graphql@16.9.0) graphql: specifier: ^16.9.0 version: 16.9.0 @@ -303,9 +306,9 @@ importers: typescript: specifier: ^5.5.3 version: 5.6.3 - vite-plugin-graphql-loader: - specifier: ^4.0.4 - version: 4.0.4 + vite-plugin-string: + specifier: ^1.2.3 + version: 1.2.3(rollup@4.21.2)(vite@5.4.8(@types/node@22.7.5)) vitest: specifier: ^2.0.3 version: 2.1.2(@types/node@22.7.5)(happy-dom@15.7.4)(msw@2.4.9(typescript@5.6.3)) @@ -978,11 +981,23 @@ packages: peerDependencies: graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 + '@graphql-tools/merge@9.0.8': + resolution: {integrity: sha512-RG9NEp4fi0MoFi0te4ahqTMYuavQnXlpEZxxMomdCa6CI5tfekcVm/rsLF5Zt8O4HY+esDt9+4dCL+aOKvG79w==} + engines: {node: '>=16.0.0'} + peerDependencies: + graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 + '@graphql-tools/schema@9.0.19': resolution: {integrity: sha512-oBRPoNBtCkk0zbUsyP4GaIzCt8C0aCI4ycIRUL67KK5pOHljKLBBtGT+Jr6hkzA74C8Gco8bpZPe7aWFjiaK2w==} peerDependencies: graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 + '@graphql-tools/utils@10.5.5': + resolution: {integrity: sha512-LF/UDWmMT0mnobL2UZETwYghV7HYBzNaGj0SAkCYOMy/C3+6sQdbcTksnoFaKR9XIVD78jNXEGfivbB8Zd+cwA==} + engines: {node: '>=16.0.0'} + peerDependencies: + graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 + '@graphql-tools/utils@9.2.1': resolution: {integrity: sha512-WUw506Ql6xzmOORlriNrD6Ugx+HjVgYxt9KCXD9mHAak+eaXSwuGGPyE60hy9xaDEoXKBsG7SkG69ybitaVl6A==} peerDependencies: @@ -1136,6 +1151,15 @@ packages: '@protobufjs/utf8@1.1.0': resolution: {integrity: sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==} + '@rollup/pluginutils@5.1.3': + resolution: {integrity: sha512-Pnsb6f32CD2W3uCaLZIzDmeFyQ2b8UWMFI7xtwUezpcGBDVDW6y9XgAWIlARiGAo6eNF5FK5aQTr0LFyNyqq5A==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + '@rollup/rollup-android-arm-eabi@4.21.2': resolution: {integrity: sha512-fSuPrt0ZO8uXeS+xP3b+yYTCBUd05MoSp2N/MFOgjhhUhMmchXlpTQrTpI8T+YAwAQuK7MafsCOxW7VrPMrJcg==} cpu: [arm] @@ -1844,6 +1868,10 @@ packages: create-color@2.0.6: resolution: {integrity: sha512-Yt2zNH+mYsWZJeOrVmwZ2OJFqJ4a6KlmjYxZCNgKz4HRz0+l1nl2r4hz9JP/SSxUELCxfUzFJi4OF8aDbL5Jnw==} + cross-inspect@1.0.1: + resolution: {integrity: sha512-Pcw1JTvZLSJH83iiGWt6fRcT+BjZlCDRVwYLbUcHzv/CRpB7r0MlSrGbIyQvVSNyGnbt7G4AXuyCiDR3POvZ1A==} + engines: {node: '>=16.0.0'} + cross-spawn@7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -1942,6 +1970,10 @@ packages: dom-helpers@5.2.1: resolution: {integrity: sha512-nRCa7CK3VTrM2NmGkIy4cbK7IZlgBE/PYMn55rrXefr5xXDP0LdtfPnblFDoVdcAfslJ7or6iqAUnx0CCGIWQA==} + dset@3.1.4: + resolution: {integrity: sha512-2QF/g9/zTaPDc3BjNcVTGoBbXBgYfMTTceLaYcFJ/W9kggFUkhxD/hMEeuLKbugyef9SqAx8cpgwlIP/jinUTA==} + engines: {node: '>=4'} + eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} @@ -2112,6 +2144,9 @@ packages: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} + estree-walker@2.0.2: + resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} + estree-walker@3.0.3: resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} @@ -3557,8 +3592,10 @@ packages: engines: {node: ^18.0.0 || >=20.0.0} hasBin: true - vite-plugin-graphql-loader@4.0.4: - resolution: {integrity: sha512-lYnpQ2luV2fcuXmOJADljuktfMbDW00Y+6QS+Ek8Jz1Vdzlj/51LSGJwZqyjJ24a5YQ+o29Hr6el/5+nlZetvg==} + vite-plugin-string@1.2.3: + resolution: {integrity: sha512-zw2jL0c4B6CAvxO8PshX04494jTcqJjNH2kW1AugBH+fImRY0evdNtVgmeS1i1VFdua/OFhL7fMqIPh0uF21/Q==} + peerDependencies: + vite: '>=2' vite-tsconfig-paths@4.3.2: resolution: {integrity: sha512-0Vd/a6po6Q+86rPlntHye7F31zA2URZMbH8M3saAZ/xR9QoGN/L21bxEGfXdWmFdNkqPpRdxFT7nmNe12e9/uA==} @@ -4345,6 +4382,12 @@ snapshots: graphql: 16.9.0 tslib: 2.7.0 + '@graphql-tools/merge@9.0.8(graphql@16.9.0)': + dependencies: + '@graphql-tools/utils': 10.5.5(graphql@16.9.0) + graphql: 16.9.0 + tslib: 2.7.0 + '@graphql-tools/schema@9.0.19(graphql@16.9.0)': dependencies: '@graphql-tools/merge': 8.4.2(graphql@16.9.0) @@ -4353,6 +4396,14 @@ snapshots: tslib: 2.7.0 value-or-promise: 1.0.12 + '@graphql-tools/utils@10.5.5(graphql@16.9.0)': + dependencies: + '@graphql-typed-document-node/core': 3.2.0(graphql@16.9.0) + cross-inspect: 1.0.1 + dset: 3.1.4 + graphql: 16.9.0 + tslib: 2.7.0 + '@graphql-tools/utils@9.2.1(graphql@16.9.0)': dependencies: '@graphql-typed-document-node/core': 3.2.0(graphql@16.9.0) @@ -4508,6 +4559,14 @@ snapshots: '@protobufjs/utf8@1.1.0': {} + '@rollup/pluginutils@5.1.3(rollup@4.21.2)': + dependencies: + '@types/estree': 1.0.6 + estree-walker: 2.0.2 + picomatch: 4.0.2 + optionalDependencies: + rollup: 4.21.2 + '@rollup/rollup-android-arm-eabi@4.21.2': optional: true @@ -5267,6 +5326,10 @@ snapshots: create-color@2.0.6: {} + cross-inspect@1.0.1: + dependencies: + tslib: 2.7.0 + cross-spawn@7.0.3: dependencies: path-key: 3.1.1 @@ -5348,6 +5411,8 @@ snapshots: '@babel/runtime': 7.25.7 csstype: 3.1.3 + dset@3.1.4: {} + eastasianwidth@0.2.0: {} ee-first@1.1.1: {} @@ -5656,6 +5721,8 @@ snapshots: estraverse@5.3.0: {} + estree-walker@2.0.2: {} + estree-walker@3.0.3: dependencies: '@types/estree': 1.0.6 @@ -7100,11 +7167,12 @@ snapshots: - supports-color - terser - vite-plugin-graphql-loader@4.0.4: + vite-plugin-string@1.2.3(rollup@4.21.2)(vite@5.4.8(@types/node@22.7.5)): dependencies: - graphql: 16.9.0 - graphql-tag: 2.12.6(graphql@16.9.0) - magic-string: 0.30.11 + '@rollup/pluginutils': 5.1.3(rollup@4.21.2) + vite: 5.4.8(@types/node@22.7.5) + transitivePeerDependencies: + - rollup vite-tsconfig-paths@4.3.2(typescript@5.6.3)(vite@5.4.8(@types/node@22.7.5)): dependencies: