Skip to content

Commit

Permalink
gql cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Jul 2, 2024
1 parent 54d47fd commit 7691b8e
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 180 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"memoizee": "^0.4.15"
},
"devDependencies": {
"@chax-at/transactional-prisma-testing": "^0.5.0",
"@chax-at/transactional-prisma-testing": "^1.2.0",
"@faker-js/faker": "^7.5.0",
"@types/aws-lambda": "^8.10.70",
"@types/memoizee": "^0.4.7",
Expand Down
6 changes: 3 additions & 3 deletions backend/src/api/resolver/greeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { defaultAppSyncMiddleware } from '@backend/middleware/lambda';
import { logger } from '@backend/util/logger';
import { incrementMetric } from '@backend/util/metrics';
import { AppSyncResolverEvent } from 'aws-lambda';
import { GQL } from '@common/index';
import { GreetingResponse, GreetingState, MutationGreetArgs } from 'common/generated/graphql/graphql';

export const GREETING = 'Yo yo';

// sample query
export const getGreeting = (): GQL.GreetingState => ({
export const getGreeting = (): GreetingState => ({
currentGreeting: GREETING,
});

// sample mutation
export const greetInner = async ({
arguments: { name },
}: AppSyncResolverEvent<GQL.MutationGreetArgs>): Promise<GQL.GreetingResponse> => {
}: AppSyncResolverEvent<MutationGreetArgs>): Promise<GreetingResponse> => {
incrementMetric('SaidHello');
logger.debug('Saying greeting to', { name });

Expand Down
27 changes: 4 additions & 23 deletions backend/src/db/runMigrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,18 @@ import { Migrate } from '@prisma/migrate/dist/Migrate.js';
import { ensureDatabaseExists } from '@prisma/migrate/dist/utils/ensureDatabaseExists';
import { printFilesFromMigrationIds } from '@prisma/migrate/dist/utils/printFiles';
import chalk from 'chalk';
import { isProd, sleep } from '@common/index';
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
import { Prisma, PrismaClient } from '@prisma/client';
import { isProd } from '@common/env';

export const handler = async (): Promise<string> => {
const schemaPath = '/var/task/backend/prisma/schema.prisma';
const dbUrl = await loadDatabaseUrl();

// get DB connection
try {
await createDbIfNotExists(dbUrl);
const client = new PrismaClient();
await client.$connect();
} catch (ex) {
const errorCode = (ex as Prisma.PrismaClientInitializationError).errorCode;
if (errorCode == 'P1001') {
// timed out waiting to reach DB server
// it might be waking up from slumber
// so retry in a short bit
console.warn('Database not yet available, retrying...');
await sleep(30_000);
console.info('Retrying...');

await createDbIfNotExists(dbUrl);
const client = new PrismaClient();
await client.$connect();
} else {
console.error('Failed to run database migrations');
throw ex;
}
}
await createDbIfNotExists(dbUrl);
const client = new PrismaClient();
await client.$connect();

process.env.DATABASE_URL = dbUrl;

Expand Down
2 changes: 1 addition & 1 deletion common/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/
graphql/generated
generated
2 changes: 0 additions & 2 deletions common/src/gql.ts

This file was deleted.

50 changes: 0 additions & 50 deletions graphql/codegen-config.cjs

This file was deleted.

8 changes: 4 additions & 4 deletions graphql/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
overwrite: true,
schema: '../graphql/schema/*.graphql',
documents: '../graphql/documents/*.graphql',
schema: './graphql/schema/*.graphql',
documents: './graphql/documents/*.graphql',
generates: {
'src/generated/gql/': {
'common/src/generated/graphql/': {
preset: 'client',
plugins: [],
},
// output combined graphql schema
'../graphql/generated/schema.graphql': {
'./graphql/generated/schema.graphql': {
config: {
// include AppSync directives in the generated schema
includeDirectives: true,
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"type": "module",
"scripts": {
"postinstall": "pnpm generate:all",
"dev": "pnpm dev:sst",
"dev:sst": "sst dev",
"dev:web": "pnpm run -C web dev",
Expand All @@ -16,9 +17,8 @@
"db:reset": "pnpm -C backend dropcreatedb:docker",
"db:generate": "pnpm run --filter backend generate",
"generate:all": "pnpm exec concurrently -c green.bold,blue.bold pnpm:db:generate pnpm:generate-graphql-schema",
"generate-graphql-schema": "graphql-codegen-esm --config common/graphql/codegen-config.cjs",
"generate-graphql-schema": "graphql-codegen-esm --config graphql/codegen.ts",
"generate": "pnpm generate:all",
"postinstall": "pnpm run generate",
"test": "pnpm testall",
"test:ci": "pnpm test",
"testall": "pnpm tsc && pnpm test:backend && pnpm test:web",
Expand Down Expand Up @@ -56,8 +56,8 @@
"@tsconfig/node20": "^1.0.0",
"@types/aws-lambda": "^8.10.140",
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"aws-cdk": "2.142.1",
"aws-cdk-lib": "2.142.1",
"concurrently": "^8.2.2",
Expand All @@ -69,7 +69,7 @@
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.30.0",
"eslint-plugin-react-hooks": "^4.5.0",
Expand Down
Loading

0 comments on commit 7691b8e

Please sign in to comment.