Skip to content

Commit

Permalink
chore: fix scripts, broken code and add command to ensure gql schema
Browse files Browse the repository at this point in the history
- houdini would crash on build if no schema was present, which makes sense : the init script now has a graphql section where if the api is not generated (and by extension the schema), it runs the schema generation if the `--no-gql` arg is not present

- few script enhancements :
  - progresser function to have a neat way of displaying progress, done status, and time took
  - args are clearly defined now
  - rawArgs are also available

- removed gulp-typescript, as it added a whole dep for basically only a fancy way of getting `'./dist'` which will never change anyway
  • Loading branch information
V-ed committed Aug 11, 2023
1 parent 043c156 commit 518e9c8
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 101 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/deploy-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ jobs:
run: |
echo "git_head_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Init
run: pnpm run init --no-api --no-client

- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
id: vercel-action
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
run: pnpm install

- name: Init
run: pnpm run init --no-api --no-client
run: pnpm run init --no-api

- name: Build
run: pnpm run --filter ./client build
Expand Down
11 changes: 7 additions & 4 deletions api/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ import { exec as execNoPromise } from 'child_process';
import del from 'del';
import fs from 'fs';
import gulp, { type TaskFunction } from 'gulp';
import ts from 'gulp-typescript';
import util from 'util';
import { generate as generatePrisma, pushDb, seedDb } from './prisma/utils/functions';

const exec = util.promisify(execNoPromise);

// CONFIGS

const tsProject = ts.createProject('./tsconfig.json');

export const configs = {
buildDest: (tsProject.config.compilerOptions?.outDir as string) || './dist',
buildDest: './dist',
uploadsFolder: './uploads',
devPort: 3005,
prismaGeneratedFolder: 'src/_generated',
Expand Down Expand Up @@ -43,6 +40,10 @@ function setupEnv() {
return Promise.resolve();
}

function generateGraphQLSchema() {
return exec('pnpm exec nest start --entryFile="@common/graphql/schema/generate-schema"');
}

function generatePrismaHelpers() {
return generatePrisma();
}
Expand Down Expand Up @@ -95,6 +96,8 @@ export const seed: TaskFunction = seedDatabase;

export const cleanSeed: TaskFunction = gulp.series(cleanDb, seedDatabase);

export const setupGQLSchema: TaskFunction = gulp.series(setupPrisma, generateGraphQLSchema);

// Useful commands

export { deleteDist, setupEnv };
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"clean:db": "gulp cleanDb",
"delete:dist": "gulp deleteDist",
"generate": "gulp setupPrisma",
"gql:generate": "gulp setupGQLSchema",
"lint": "npm-run-all -p lint:*",
"lint:src": "eslint \"{src,apps,libs}/**/*.ts\"",
"lint:tests": "eslint \"tests/**/*.ts\"",
Expand Down Expand Up @@ -84,7 +85,6 @@
"graphql-config": "5.0.2",
"graphql-tag": "2.12.6",
"gulp": "4.0.2",
"gulp-typescript": "6.0.0-alpha.1",
"prisma": "4.16.2",
"prisma-fixtures": "0.1.15",
"prisma-nestjs-graphql": "18.0.2",
Expand Down
5 changes: 5 additions & 0 deletions api/src/@common/graphql/schema/generate-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'reflect-metadata';

import { ensureGraphQLSchema } from './schema.manager';

ensureGraphQLSchema();
14 changes: 14 additions & 0 deletions api/src/@common/graphql/schema/schema.manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { schemaPath } from '$graphql/graphql.module';
import { NestFactory } from '@nestjs/core';
import { existsSync } from 'fs';
import { AppModule } from '~/app.module';

export async function ensureGraphQLSchema() {
if (!existsSync(schemaPath)) {
// If schema file doesn't exist, run app once to generate schema
const tempGqlApp = await NestFactory.create(AppModule);

await tempGqlApp.init();
await tempGqlApp.close();
}
}
8 changes: 7 additions & 1 deletion api/src/@common/prisma/prisma.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ export class PrismaService extends PrismaClient implements OnModuleInit, OnModul
}

async onModuleInit(): Promise<void> {
await this.$connect();
await this.$connect().catch((error) => {
if (process.env.CI) {
return;
}

throw error;
});
}

async onModuleDestroy(): Promise<void> {
Expand Down
15 changes: 2 additions & 13 deletions api/tests/utils/E2ETestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import 'lucia/polyfill/node';

import { AuthModule } from '$auth/auth.module';
import { AuthService } from '$auth/auth.service';
import { GraphQLModule, schemaPath } from '$graphql/graphql.module';
import { GraphQLModule } from '$graphql/graphql.module';
import { ensureGraphQLSchema } from '$graphql/schema/schema.manager';
import { PrismaModule } from '$prisma/prisma.module';
import { PrismaService } from '$prisma/prisma.service';
import { setupViewEngine } from '$utils/setupViewEngine';
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { TestingModuleBuilder } from '@nestjs/testing';
import { existsSync } from 'fs';
import { User } from 'lucia';
import supertest from 'supertest';
import supertestGQL, { Variables } from 'supertest-graphql';
Expand Down Expand Up @@ -177,13 +176,3 @@ export class E2ETestManager extends TestManager<E2ETestOptions> {
this.authToken = session.sessionId;
}
}

export async function ensureGraphQLSchema() {
if (!existsSync(schemaPath)) {
// If schema file doesn't exist, run app once to generate schema
const tempGqlApp = await NestFactory.create(AppModule);

await tempGqlApp.init();
await tempGqlApp.close();
}
}
4 changes: 1 addition & 3 deletions api/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"node_modules",
"tests",
"dist",
"**/*spec.ts",
".graphqlrc.ts",
"gulpfile.ts",
"**/*.spec.ts",
]
}
3 changes: 2 additions & 1 deletion client/src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { parseString } from 'set-cookie-parser';
import type { AppLocals } from './app';
import { createHoudiniHelpers } from './lib/houdini/helper';
import { themeCookieName, themes, type Theme } from './lib/stores';
import { AUTH_COOKIE_NAME } from './lib/utils/auth';

export const AUTH_COOKIE_NAME = 'auth_session';

export async function getAuthUser(query: AppLocals['gql']['query']) {
const result = await query(GetUserFromSessionStore);
Expand Down
16 changes: 3 additions & 13 deletions client/src/lib/components/nav/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import type { ClientUser } from '$/hooks.server';
import { navElements } from '$/navigation';
import { browser } from '$app/environment';
import { applyAction, enhance } from '$app/forms';
import { enhance } from '$app/forms';
import { page } from '$app/stores';
import { isDrawerHidden, sessionToken } from '$lib/stores';
import { isDrawerHidden } from '$lib/stores';
import { mdiLogout } from '@mdi/js';
import {
Avatar,
Expand All @@ -26,16 +26,6 @@
import { isNavElemVisible } from './utils';
export let sessionUser: ClientUser;
const enhanceLogout: Parameters<typeof enhance>[1] = () => {
return async ({ result }) => {
if (result.type == 'success' || result.type == 'redirect') {
sessionToken.set(null);
}
await applyAction(result);
};
};
</script>

<Navbar
Expand All @@ -53,7 +43,7 @@
{#if sessionUser}
<Avatar class="cursor-pointer" id="avatar-menu" src="https://static-00.iconduck.com/assets.00/user-icon-2048x2048-ihoxz4vq.png" />

<form method="POST" action="/?/logout" use:enhance={enhanceLogout}>
<form method="POST" action="/?/logout" use:enhance>
<Button type="submit" outline={true} class="!p-2 ml-3" size="lg">
<Icon path={mdiLogout} />
</Button>
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"./client"
],
"scripts": {
"init": "ts-node-esm ./scripts/init.ts",
"init": "ts-node ./scripts/init.ts",
"gql": "graphql-codegen --config .graphqlrc.ts",
"gql:watch": "pnpm gql --watch"
},
Expand Down Expand Up @@ -45,9 +45,6 @@
"stylelint": {
"extends": [
"@v-ed/stylelint-config"
],
"ignoreFiles": [
"./client/static/theme/**/*"
]
},
"devDependencies": {
Expand Down
57 changes: 28 additions & 29 deletions pnpm-lock.yaml

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

Loading

0 comments on commit 518e9c8

Please sign in to comment.