From 8d879ba981f8e0aa16e9d6b1d5f7666301710f6d Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Tue, 16 May 2023 16:36:53 +0200 Subject: [PATCH] Add graqhql introspection schema --- .gitignore | 1 + client/codegen.ts | 5 ++++- client/minimizeGraphqlSchema.mjs | 11 +++++++++++ client/package-lock.json | 14 ++++++++++++++ client/package.json | 7 ++++--- {server => client/src/gql}/schema.graphql | 0 client/src/graphql/client.ts | 5 +++++ server/.graphqlconfig | 15 --------------- server/config/settings/base.py | 2 +- server/graphql.config.yml | 8 ++++++++ 10 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 client/minimizeGraphqlSchema.mjs rename {server => client/src/gql}/schema.graphql (100%) delete mode 100644 server/.graphqlconfig create mode 100644 server/graphql.config.yml diff --git a/.gitignore b/.gitignore index a5e6f819..3d1e0c04 100644 --- a/.gitignore +++ b/.gitignore @@ -289,3 +289,4 @@ git-crypt-encrypted-files-check.txt /server/vbv_lernwelt/static/vue/ /server/vbv_lernwelt/templates/vue/index.html /server/vbv_lernwelt/media +/client/src/gql/minifiedSchema.json diff --git a/client/codegen.ts b/client/codegen.ts index 5d95944d..0ace6d9f 100644 --- a/client/codegen.ts +++ b/client/codegen.ts @@ -1,9 +1,12 @@ import type { CodegenConfig } from "@graphql-codegen/cli"; const config: CodegenConfig = { - schema: "../server/schema.graphql", + schema: "./src/gql/schema.graphql", documents: ["src/**/*.vue", "src/graphql/**/*.ts"], ignoreNoDocuments: true, + hooks: { + afterAllFileWrite: ["node minimizeGraphqlSchema.mjs"], + }, generates: { "./src/gql/": { preset: "client", diff --git a/client/minimizeGraphqlSchema.mjs b/client/minimizeGraphqlSchema.mjs new file mode 100644 index 00000000..b4f5f7e7 --- /dev/null +++ b/client/minimizeGraphqlSchema.mjs @@ -0,0 +1,11 @@ +import { getIntrospectedSchema, minifyIntrospectionQuery } from "@urql/introspection"; +import { readFileSync, writeFileSync } from "fs"; + +// Read the existing introspection schema +const schema = readFileSync("./src/gql/schema.graphql", "utf-8"); +// const schema = JSON.parse(schemaJson); + +const minifiedSchema = minifyIntrospectionQuery(getIntrospectedSchema(schema)); + +// Write the minified schema to a new file +writeFileSync("./src/gql/minifiedSchema.json", JSON.stringify(minifiedSchema)); diff --git a/client/package-lock.json b/client/package-lock.json index 43dd9f8d..e99c1c09 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -14,6 +14,7 @@ "@sentry/vue": "^7.20.0", "@urql/devtools": "^2.0.3", "@urql/exchange-graphcache": "^6.0.4", + "@urql/introspection": "^1.0.2", "@urql/vue": "^1.1.1", "@vueuse/core": "^9.13.0", "@vueuse/router": "^10.1.2", @@ -7041,6 +7042,14 @@ "wonka": "^6.3.2" } }, + "node_modules/@urql/introspection": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@urql/introspection/-/introspection-1.0.2.tgz", + "integrity": "sha512-vPuX+DjbmL5EUsvwgAMV8dkxc7JKuuNTzDfsNvtCuVmbAED4Nx39p08HImjTWAewSatjyzZZs+fAhU7z/4P+UQ==", + "peerDependencies": { + "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" + } + }, "node_modules/@urql/vue": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@urql/vue/-/vue-1.1.1.tgz", @@ -24994,6 +25003,11 @@ "wonka": "^6.3.2" } }, + "@urql/introspection": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@urql/introspection/-/introspection-1.0.2.tgz", + "integrity": "sha512-vPuX+DjbmL5EUsvwgAMV8dkxc7JKuuNTzDfsNvtCuVmbAED4Nx39p08HImjTWAewSatjyzZZs+fAhU7z/4P+UQ==" + }, "@urql/vue": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@urql/vue/-/vue-1.1.1.tgz", diff --git a/client/package.json b/client/package.json index e3f60e3c..2191a45b 100644 --- a/client/package.json +++ b/client/package.json @@ -2,10 +2,10 @@ "name": "client", "version": "0.0.0", "scripts": { - "build": "vue-tsc --noEmit && vite build && node versionize && cp ./dist/index.html ../server/vbv_lernwelt/templates/vue/index.html && rm -rf ../server/vbv_lernwelt/static/vue/* && cp -r ./dist/static/vue ../server/vbv_lernwelt/static/ && npm run build-storybook", + "build": "npm run codegen && vue-tsc --noEmit && vite build && node versionize && cp ./dist/index.html ../server/vbv_lernwelt/templates/vue/index.html && rm -rf ../server/vbv_lernwelt/static/vue/* && cp -r ./dist/static/vue ../server/vbv_lernwelt/static/ && npm run build-storybook", "build-storybook": "rm -rf ../server/vbv_lernwelt/static/storybook/* && storybook build -o ../server/vbv_lernwelt/static/storybook", "build:tailwind": "tailwindcss -i tailwind.css -o ../server/vbv_lernwelt/static/css/tailwind.css --minify", - "codegen": "graphql-codegen", + "codegen": "graphql-codegen && node minimizeGraphqlSchema.mjs", "codegen:watch": "graphql-codegen --watch", "coverage": "vitest run --coverage", "cypress:open": "cypress open", @@ -16,7 +16,7 @@ "storybook": "storybook dev -p 6006", "tailwind": "tailwindcss -i tailwind.css -o ../server/vbv_lernwelt/static/css/tailwind.css --watch", "test": "vitest run", - "typecheck": "vue-tsc --noEmit -p tsconfig.app.json --composite false", + "typecheck": "npm run codegen && vue-tsc --noEmit -p tsconfig.app.json --composite false", "vue-i18n-extract": "vue-i18n-extract report" }, "dependencies": { @@ -26,6 +26,7 @@ "@sentry/vue": "^7.20.0", "@urql/devtools": "^2.0.3", "@urql/exchange-graphcache": "^6.0.4", + "@urql/introspection": "^1.0.2", "@urql/vue": "^1.1.1", "@vueuse/core": "^9.13.0", "@vueuse/router": "^10.1.2", diff --git a/server/schema.graphql b/client/src/gql/schema.graphql similarity index 100% rename from server/schema.graphql rename to client/src/gql/schema.graphql diff --git a/client/src/graphql/client.ts b/client/src/graphql/client.ts index c0daffa7..da7eebd8 100644 --- a/client/src/graphql/client.ts +++ b/client/src/graphql/client.ts @@ -1,3 +1,7 @@ +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +import schema from "../gql/minifiedSchema.json"; + import { devtoolsExchange } from "@urql/devtools"; import { cacheExchange } from "@urql/exchange-graphcache"; import { Client, fetchExchange } from "@urql/vue"; @@ -7,6 +11,7 @@ export const graphqlClient = new Client({ exchanges: [ devtoolsExchange, cacheExchange({ + schema: schema, updates: { Mutation: { // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/server/.graphqlconfig b/server/.graphqlconfig deleted file mode 100644 index b580e254..00000000 --- a/server/.graphqlconfig +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "VBV Schema", - "schemaPath": "schema.graphql", - "extensions": { - "endpoints": { - "Default GraphQL Endpoint": { - "url": "http://localhost:8000/server/graphql/", - "headers": { - "user-agent": "JS GraphQL" - }, - "introspect": false - } - } - } -} diff --git a/server/config/settings/base.py b/server/config/settings/base.py index bc4da56b..11b0c53d 100644 --- a/server/config/settings/base.py +++ b/server/config/settings/base.py @@ -568,7 +568,7 @@ OAUTH = { GRAPHENE = { "SCHEMA": "vbv_lernwelt.core.schema.schema", - "SCHEMA_OUTPUT": "schema.graphql", + "SCHEMA_OUTPUT": "../client/src/gql/schema.graphql", } # GRAPPLE = { # "EXPOSE_GRAPHIQL": DEBUG, diff --git a/server/graphql.config.yml b/server/graphql.config.yml new file mode 100644 index 00000000..17bb163b --- /dev/null +++ b/server/graphql.config.yml @@ -0,0 +1,8 @@ +schema: client/src/gql/schema.graphql +extensions: + endpoints: + Default GraphQL Endpoint: + url: http://localhost:8000/server/graphql/ + headers: + user-agent: JS GraphQL + introspect: true