Skip to content
This repository was archived by the owner on Dec 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/graphql-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -25,6 +25,7 @@
"test": "vitest run"
},
"dependencies": {
"@graphql-tools/merge": "^9.0.8",
"graphql": "^16.9.0"
},
"devDependencies": {
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-config/src/graphql.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module "*.graphql" {
const Document: import("graphql").DocumentNode;
const Document: string;
export default Document;
}
9 changes: 9 additions & 0 deletions packages/graphql-config/src/schema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { describe, it, expect } from "vitest";
import { buildASTSchema } from "graphql";
import { schemaDefinition } from "./schema";

describe.skip("schemaDefinition", () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to remove skip here when I work on #56.

it("should be buildable", () => {
expect(buildASTSchema(schemaDefinition)).not.toThrow();
});
});
23 changes: 12 additions & 11 deletions packages/graphql-config/src/schema.ts
Original file line number Diff line number Diff line change
@@ -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),
});
Comment on lines -7 to -10

@IzumiSy IzumiSy Oct 28, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found that merging like this is not working as expected, so now here is using use @graphql-tools/merge instead.

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,
]),
);
10 changes: 8 additions & 2 deletions packages/graphql-config/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -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"],
},
Expand Down
86 changes: 77 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.