Skip to content

Commit

Permalink
Fixed codegen in build and rewrited logic of codegen apply via vite p…
Browse files Browse the repository at this point in the history
…lugin (#181)
  • Loading branch information
mhevyk authored Sep 13, 2024
1 parent 25d1052 commit 08962b1
Show file tree
Hide file tree
Showing 8 changed files with 770 additions and 156 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ jobs:
- name: Install dependencies
run: npm install

- name: Generate api requests
env:
VITE_GRAPHQL_API_URL: ${{ secrets.VITE_GRAPHQL_API_URL }}
run: npm run codegen

- name: Lint
run: npm run lint:check

- name: Run tests
env:
VITE_GRAPHQL_API_URL: ${{ secrets.VITE_GRAPHQL_API_URL }}
run: npm run test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dist
dist-ssr
*.local

vite.config.ts.timestamp*

# Editor directories and files
.vscode/*
!.vscode/extensions.json
Expand Down
19 changes: 15 additions & 4 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import { CodegenConfig } from "@graphql-codegen/cli";
import dotenv from "dotenv";
import fs from "fs";
import path from "path";

dotenv.config();
const mode = process.env.NODE_ENV ?? "development";
const isProduction = mode === "production";

if (fs.existsSync(".env.development")) {
dotenv.config({ path: ".env.development" });
const generatesFile = isProduction
? "dist/temp_api/index.tsx"
: "src/api/generated/index.tsx";

const envFiles = [".env", `.env.${mode}`];
for (const envFile of envFiles) {
const envPath = path.resolve(__dirname, envFile);

if (fs.existsSync(envPath)) {
dotenv.config({ path: envPath });
}
}

const config: CodegenConfig = {
schema: process.env.VITE_GRAPHQL_API_URL,
overwrite: true,
documents: ["src/api/graphql/*.graphql"],
generates: {
"src/api/generated/index.tsx": {
[generatesFile]: {
plugins: [
"typescript",
"typescript-operations",
Expand Down
Loading

0 comments on commit 08962b1

Please sign in to comment.