create-joist-app 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +51 -32
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/basic/README.md +70 -0
- package/templates/basic/gitignore +28 -0
- package/templates/basic/jest.config.js +14 -0
- package/templates/basic/joist-config.json +7 -0
- package/templates/basic/migrations/1580658856631_initial.ts +22 -0
- package/templates/basic/package.json +28 -0
- package/templates/basic/src/context.ts +14 -0
- package/templates/basic/src/entities/Author.test.ts +17 -0
- package/templates/basic/src/entities/Author.ts +7 -0
- package/templates/basic/src/entities/Book.ts +3 -0
- package/templates/basic/src/entities/entities.ts +14 -0
- package/templates/basic/src/entities/factories/index.ts +2 -0
- package/templates/basic/src/entities/factories/newAuthor.ts +6 -0
- package/templates/basic/src/entities/factories/newBook.ts +6 -0
- package/templates/basic/src/entities/index.ts +3 -0
- package/templates/basic/src/setupTestEnv.ts +5 -0
- package/templates/basic/src/setupTests.ts +29 -0
- package/templates/basic/tsconfig.json +23 -0
- package/templates/graphql/README.md +84 -0
- package/templates/graphql/codegen.yml +11 -0
- package/templates/graphql/gitignore +28 -0
- package/templates/graphql/graphql-codegen-joist.js +5 -0
- package/templates/graphql/graphql-codegen.js +26 -0
- package/templates/graphql/jest.config.js +14 -0
- package/templates/graphql/joist-config.json +8 -0
- package/templates/graphql/migrations/1580658856631_initial.ts +38 -0
- package/templates/graphql/package.json +41 -0
- package/templates/graphql/schema/.history.json +9 -0
- package/templates/graphql/schema/author.graphql +20 -0
- package/templates/graphql/schema/book.graphql +19 -0
- package/templates/graphql/schema/enums.graphql +0 -0
- package/templates/graphql/schema/root.graphql +0 -0
- package/templates/graphql/src/.history.json +12 -0
- package/templates/graphql/src/context.ts +14 -0
- package/templates/graphql/src/entities/Author.test.ts +36 -0
- package/templates/graphql/src/entities/Author.ts +7 -0
- package/templates/graphql/src/entities/Book.ts +3 -0
- package/templates/graphql/src/entities/entities.ts +14 -0
- package/templates/graphql/src/entities/factories/index.ts +2 -0
- package/templates/graphql/src/entities/factories/newAuthor.ts +6 -0
- package/templates/graphql/src/entities/factories/newBook.ts +6 -0
- package/templates/graphql/src/entities/index.ts +3 -0
- package/templates/graphql/src/jest.d.ts +9 -0
- package/templates/graphql/src/resolvers/author/authorResolvers.test.ts +17 -0
- package/templates/graphql/src/resolvers/author/authorResolvers.ts +5 -0
- package/templates/graphql/src/resolvers/author/saveAuthorMutation.test.ts +13 -0
- package/templates/graphql/src/resolvers/author/saveAuthorMutation.ts +9 -0
- package/templates/graphql/src/resolvers/book/bookResolvers.test.ts +17 -0
- package/templates/graphql/src/resolvers/book/bookResolvers.ts +5 -0
- package/templates/graphql/src/resolvers/book/saveBookMutation.test.ts +16 -0
- package/templates/graphql/src/resolvers/book/saveBookMutation.ts +9 -0
- package/templates/graphql/src/resolvers/enumResolvers.ts +5 -0
- package/templates/graphql/src/resolvers/index.ts +15 -0
- package/templates/graphql/src/resolvers/mutations/index.ts +7 -0
- package/templates/graphql/src/resolvers/objects/index.ts +6 -0
- package/templates/graphql/src/resolvers/testUtils.ts +10 -0
- package/templates/graphql/src/resolvers/utils.ts +1 -0
- package/templates/graphql/src/server.ts +37 -0
- package/templates/graphql/src/setupIt.ts +17 -0
- package/templates/graphql/src/setupTestEnv.ts +5 -0
- package/templates/graphql/src/setupTests.ts +37 -0
- package/templates/graphql/tsconfig.json +23 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCreatedAtFunction,
|
|
3
|
+
createEntityTable,
|
|
4
|
+
createUpdatedAtFunction,
|
|
5
|
+
foreignKey,
|
|
6
|
+
} from "joist-migration-utils";
|
|
7
|
+
import { MigrationBuilder } from "node-pg-migrate";
|
|
8
|
+
|
|
9
|
+
export function up(b: MigrationBuilder): void {
|
|
10
|
+
createUpdatedAtFunction(b);
|
|
11
|
+
createCreatedAtFunction(b);
|
|
12
|
+
|
|
13
|
+
// Create flush_database function for test cleanup
|
|
14
|
+
b.sql(`
|
|
15
|
+
CREATE OR REPLACE FUNCTION flush_database() RETURNS void AS $$
|
|
16
|
+
DECLARE
|
|
17
|
+
tables CURSOR FOR
|
|
18
|
+
SELECT tablename FROM pg_tables
|
|
19
|
+
WHERE schemaname = 'public'
|
|
20
|
+
AND tablename != 'pgmigrations';
|
|
21
|
+
BEGIN
|
|
22
|
+
FOR t IN tables LOOP
|
|
23
|
+
EXECUTE 'TRUNCATE TABLE ' || quote_ident(t.tablename) || ' CASCADE';
|
|
24
|
+
END LOOP;
|
|
25
|
+
END;
|
|
26
|
+
$$ LANGUAGE plpgsql;
|
|
27
|
+
`);
|
|
28
|
+
|
|
29
|
+
createEntityTable(b, "authors", {
|
|
30
|
+
first_name: { type: "varchar(255)", notNull: true },
|
|
31
|
+
last_name: { type: "varchar(255)", notNull: false },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
createEntityTable(b, "books", {
|
|
35
|
+
title: { type: "varchar(255)", notNull: true },
|
|
36
|
+
author_id: foreignKey("authors", { notNull: true }),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "graphql-template",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc",
|
|
7
|
+
"start": "tsx src/server.ts",
|
|
8
|
+
"dev": "tsx watch src/server.ts",
|
|
9
|
+
"test": "env-cmd jest --runInBand",
|
|
10
|
+
"codegen": "env-cmd yarn joist-codegen && yarn graphql-codegen",
|
|
11
|
+
"graphql-codegen": "graphql-codegen --config graphql-codegen.js",
|
|
12
|
+
"format": "prettier --write \"src/**/*.{ts,tsx,graphql}\""
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@apollo/server": "^4.11.0",
|
|
16
|
+
"@graphql-tools/graphql-file-loader": "^8.0.0",
|
|
17
|
+
"@graphql-tools/load": "^8.0.0",
|
|
18
|
+
"@graphql-tools/merge": "^9.0.0",
|
|
19
|
+
"graphql": "^16.9.0",
|
|
20
|
+
"joist-orm": "2.0.3-next.36",
|
|
21
|
+
"knex": "^3.1.0",
|
|
22
|
+
"pg": "^8.16.3"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@graphql-codegen/cli": "^5.0.0",
|
|
26
|
+
"@graphql-codegen/typescript": "^4.0.0",
|
|
27
|
+
"@graphql-codegen/typescript-resolvers": "^4.0.0",
|
|
28
|
+
"@homebound/graphql-typescript-possible-types": "^2.19.0",
|
|
29
|
+
"@homebound/graphql-typescript-resolver-scaffolding": "^2.49.0",
|
|
30
|
+
"@homebound/graphql-typescript-simple-resolvers": "^1.58.0",
|
|
31
|
+
"@swc/core": "^1.13.0",
|
|
32
|
+
"@swc/jest": "^0.2.39",
|
|
33
|
+
"@types/jest": "^30.0.0",
|
|
34
|
+
"@types/node": "^24.0.0",
|
|
35
|
+
"env-cmd": "^11.0.0",
|
|
36
|
+
"jest": "^30.0.0",
|
|
37
|
+
"prettier": "^3.6.0",
|
|
38
|
+
"tsx": "^4.20.0",
|
|
39
|
+
"typescript": "^5.9.0"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Author": ["books", "createdAt", "firstName", "id", "lastName", "updatedAt"],
|
|
3
|
+
"Book": ["author", "createdAt", "id", "title", "updatedAt"],
|
|
4
|
+
"Mutation": ["saveAuthor", "saveBook"],
|
|
5
|
+
"SaveAuthorInput": ["firstName", "id", "lastName"],
|
|
6
|
+
"SaveAuthorResult": ["author"],
|
|
7
|
+
"SaveBookInput": ["authorId", "id", "title"],
|
|
8
|
+
"SaveBookResult": ["book"]
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
extend type Mutation {
|
|
2
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
type Author {
|
|
6
|
+
id: ID!
|
|
7
|
+
firstName: String!
|
|
8
|
+
lastName: String
|
|
9
|
+
books: [Book!]!
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
input SaveAuthorInput {
|
|
13
|
+
id: ID
|
|
14
|
+
firstName: String
|
|
15
|
+
lastName: String
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type SaveAuthorResult {
|
|
19
|
+
author: Author!
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
extend type Mutation {
|
|
2
|
+
saveBook(input: SaveBookInput!): SaveBookResult!
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
type Book {
|
|
6
|
+
id: ID!
|
|
7
|
+
title: String!
|
|
8
|
+
author: Author!
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
input SaveBookInput {
|
|
12
|
+
id: ID
|
|
13
|
+
title: String
|
|
14
|
+
authorId: ID
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type SaveBookResult {
|
|
18
|
+
book: Book!
|
|
19
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": [
|
|
3
|
+
"resolvers/author/authorResolvers.test.ts",
|
|
4
|
+
"resolvers/author/authorResolvers.ts",
|
|
5
|
+
"resolvers/author/saveAuthorMutation.test.ts",
|
|
6
|
+
"resolvers/author/saveAuthorMutation.ts",
|
|
7
|
+
"resolvers/book/bookResolvers.test.ts",
|
|
8
|
+
"resolvers/book/bookResolvers.ts",
|
|
9
|
+
"resolvers/book/saveBookMutation.test.ts",
|
|
10
|
+
"resolvers/book/saveBookMutation.ts"
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EntityManager, newPgConnectionConfig } from "joist-orm";
|
|
2
|
+
import { PostgresDriver } from "joist-orm/pg";
|
|
3
|
+
import { Pool } from "pg";
|
|
4
|
+
|
|
5
|
+
export interface Context {
|
|
6
|
+
pool: Pool;
|
|
7
|
+
em: EntityManager;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function newContext(): Context {
|
|
11
|
+
const pool = new Pool(newPgConnectionConfig());
|
|
12
|
+
const em = new EntityManager({}, new PostgresDriver(pool));
|
|
13
|
+
return { em, pool };
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { newEm } from "../setupTests";
|
|
2
|
+
import { newAuthor, newBook } from "./factories";
|
|
3
|
+
|
|
4
|
+
describe("Author", () => {
|
|
5
|
+
it("can create an author", async () => {
|
|
6
|
+
const em = newEm();
|
|
7
|
+
const author = newAuthor(em, { firstName: "John", lastName: "Doe" });
|
|
8
|
+
await em.flush();
|
|
9
|
+
|
|
10
|
+
const loaded = await em.load(author.constructor, author.id);
|
|
11
|
+
expect(loaded).toMatchEntity({ firstName: "John", lastName: "Doe" });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("has a full name", async () => {
|
|
15
|
+
const em = newEm();
|
|
16
|
+
const author = newAuthor(em, { firstName: "Jane", lastName: "Smith" });
|
|
17
|
+
expect(author.fullName).toBe("Jane Smith");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("handles missing last name in fullName", async () => {
|
|
21
|
+
const em = newEm();
|
|
22
|
+
const author = newAuthor(em, { firstName: "Jane" });
|
|
23
|
+
expect(author.fullName).toBe("Jane");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("can have books", async () => {
|
|
27
|
+
const em = newEm();
|
|
28
|
+
const author = newAuthor(em, { firstName: "Test", lastName: "Author" });
|
|
29
|
+
const book = newBook(em, { title: "Test Book", author });
|
|
30
|
+
await em.flush();
|
|
31
|
+
|
|
32
|
+
const books = await author.books.load();
|
|
33
|
+
expect(books).toHaveLength(1);
|
|
34
|
+
expect(books[0]).toMatchEntity({ title: "Test Book" });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// organize-imports-ignore
|
|
2
|
+
|
|
3
|
+
// This file drives our import order to avoid undefined errors
|
|
4
|
+
// when the subclasses extend the base classes, see:
|
|
5
|
+
// https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de
|
|
6
|
+
|
|
7
|
+
export * from "./codegen/AuthorCodegen";
|
|
8
|
+
export * from "./codegen/BookCodegen";
|
|
9
|
+
export * from "./Author";
|
|
10
|
+
export * from "./Book";
|
|
11
|
+
|
|
12
|
+
export * from "./factories/newAuthor";
|
|
13
|
+
export * from "./factories/newBook";
|
|
14
|
+
export * from "./codegen/metadata";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare namespace jest {
|
|
2
|
+
type ContextOpts = Partial<import("./context").Context & import("./context").AppContext>;
|
|
3
|
+
type itWithCtxFn = (ctx: import("./context").Context) => Promise<void>;
|
|
4
|
+
|
|
5
|
+
interface It {
|
|
6
|
+
withCtx(name: string, fn: itWithCtxFn): void;
|
|
7
|
+
withCtx(name: string, opts: ContextOpts, fn: itWithCtxFn): void;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { newAuthor } from "src/entities";
|
|
2
|
+
import { authorResolvers } from "src/resolvers/author/authorResolvers";
|
|
3
|
+
import { makeRunObjectField, makeRunObjectFields } from "src/resolvers/testUtils";
|
|
4
|
+
|
|
5
|
+
describe("authorResolvers", () => {
|
|
6
|
+
it.withCtx("can return", async (ctx) => {
|
|
7
|
+
const { em } = ctx;
|
|
8
|
+
// Given a Author
|
|
9
|
+
const a = newAuthor(em);
|
|
10
|
+
// Then we can query it
|
|
11
|
+
const result = await runFields(ctx, a, ["firstName", "lastName", "createdAt", "updatedAt"]);
|
|
12
|
+
expect(result).toMatchEntity({});
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const runFields = makeRunObjectFields(authorResolvers);
|
|
17
|
+
const runField = makeRunObjectField(authorResolvers);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { saveAuthor } from "src/resolvers/author/saveAuthorMutation";
|
|
2
|
+
import { makeRunInputMutation } from "src/resolvers/testUtils";
|
|
3
|
+
|
|
4
|
+
describe("saveAuthor", () => {
|
|
5
|
+
it.withCtx("can create", async (ctx) => {
|
|
6
|
+
const result = await runSave(ctx, () => ({
|
|
7
|
+
firstName: "Test",
|
|
8
|
+
}));
|
|
9
|
+
expect(result).toBeDefined();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const runSave = makeRunInputMutation(saveAuthor);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Author } from "src/entities";
|
|
2
|
+
import type { MutationResolvers } from "src/generated/graphql-types";
|
|
3
|
+
import { saveEntity } from "src/resolvers/utils";
|
|
4
|
+
|
|
5
|
+
export const saveAuthor: Pick<MutationResolvers, "saveAuthor"> = {
|
|
6
|
+
async saveAuthor(_, args, ctx) {
|
|
7
|
+
return { author: await saveEntity(ctx, Author, args.input) };
|
|
8
|
+
},
|
|
9
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { newBook } from "src/entities";
|
|
2
|
+
import { bookResolvers } from "src/resolvers/book/bookResolvers";
|
|
3
|
+
import { makeRunObjectField, makeRunObjectFields } from "src/resolvers/testUtils";
|
|
4
|
+
|
|
5
|
+
describe("bookResolvers", () => {
|
|
6
|
+
it.withCtx("can return", async (ctx) => {
|
|
7
|
+
const { em } = ctx;
|
|
8
|
+
// Given a Book
|
|
9
|
+
const b = newBook(em);
|
|
10
|
+
// Then we can query it
|
|
11
|
+
const result = await runFields(ctx, b, ["title", "createdAt", "updatedAt"]);
|
|
12
|
+
expect(result).toMatchEntity({});
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const runFields = makeRunObjectFields(bookResolvers);
|
|
17
|
+
const runField = makeRunObjectField(bookResolvers);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { newAuthor } from "src/entities/index";
|
|
2
|
+
import { saveBook } from "src/resolvers/book/saveBookMutation";
|
|
3
|
+
import { makeRunInputMutation } from "src/resolvers/testUtils";
|
|
4
|
+
|
|
5
|
+
describe("saveBook", () => {
|
|
6
|
+
it.withCtx("can create", async (ctx) => {
|
|
7
|
+
const a = newAuthor(ctx.em);
|
|
8
|
+
const result = await runSave(ctx, () => ({
|
|
9
|
+
title: "Test Book",
|
|
10
|
+
authorId: a.id,
|
|
11
|
+
}));
|
|
12
|
+
expect(result).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const runSave = makeRunInputMutation(saveBook);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Book } from "src/entities";
|
|
2
|
+
import type { MutationResolvers } from "src/generated/graphql-types";
|
|
3
|
+
import { saveEntity } from "src/resolvers/utils";
|
|
4
|
+
|
|
5
|
+
export const saveBook: Pick<MutationResolvers, "saveBook"> = {
|
|
6
|
+
async saveBook(_, args, ctx) {
|
|
7
|
+
return { book: await saveEntity(ctx, Book, args.input) };
|
|
8
|
+
},
|
|
9
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { authorResolvers } from "./authorResolvers";
|
|
2
|
+
import { bookResolvers } from "./bookResolvers";
|
|
3
|
+
|
|
4
|
+
export const resolvers = {
|
|
5
|
+
Query: {
|
|
6
|
+
...authorResolvers.Query,
|
|
7
|
+
...bookResolvers.Query,
|
|
8
|
+
},
|
|
9
|
+
Mutation: {
|
|
10
|
+
...authorResolvers.Mutation,
|
|
11
|
+
...bookResolvers.Mutation,
|
|
12
|
+
},
|
|
13
|
+
Author: authorResolvers.Author,
|
|
14
|
+
Book: bookResolvers.Book,
|
|
15
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MutationResolvers } from "src/generated/graphql-types";
|
|
2
|
+
import { saveAuthor } from "src/resolvers/author/saveAuthorMutation";
|
|
3
|
+
import { saveBook } from "src/resolvers/book/saveBookMutation";
|
|
4
|
+
|
|
5
|
+
// This file is auto-generated
|
|
6
|
+
|
|
7
|
+
export const mutationResolvers: MutationResolvers = { ...saveAuthor, ...saveBook };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
makeMakeRunInputMutation,
|
|
3
|
+
makeMakeRunObjectField,
|
|
4
|
+
makeMakeRunObjectFields,
|
|
5
|
+
} from "joist-graphql-resolver-utils/tests";
|
|
6
|
+
import { run } from "joist-orm/tests";
|
|
7
|
+
|
|
8
|
+
export const makeRunObjectField = makeMakeRunObjectField(run);
|
|
9
|
+
export const makeRunObjectFields = makeMakeRunObjectFields(run);
|
|
10
|
+
export const makeRunInputMutation = makeMakeRunInputMutation(run);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { entityResolver, saveEntities, saveEntity } from "joist-orm/graphql";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ApolloServer } from "@apollo/server";
|
|
2
|
+
import { startStandaloneServer } from "@apollo/server/standalone";
|
|
3
|
+
import { loadSchemaSync } from "@graphql-tools/load";
|
|
4
|
+
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
|
|
5
|
+
import { EntityManager } from "joist-orm";
|
|
6
|
+
import { newPgConnectionConfig } from "joist-orm/pg";
|
|
7
|
+
import knex from "knex";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { Context } from "./context";
|
|
10
|
+
import { entities } from "./entities";
|
|
11
|
+
import { resolvers } from "./resolvers";
|
|
12
|
+
|
|
13
|
+
const typeDefs = loadSchemaSync(path.join(__dirname, "./**/*.graphql"), {
|
|
14
|
+
loaders: [new GraphQLFileLoader()],
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
async function main() {
|
|
18
|
+
const config = newPgConnectionConfig();
|
|
19
|
+
const db = knex({ client: "pg", connection: config });
|
|
20
|
+
|
|
21
|
+
const server = new ApolloServer<Context>({
|
|
22
|
+
typeDefs,
|
|
23
|
+
resolvers,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const { url } = await startStandaloneServer(server, {
|
|
27
|
+
listen: { port: parseInt(process.env.PORT || "4000") },
|
|
28
|
+
context: async () => {
|
|
29
|
+
const em = new EntityManager({ entities, driver: db }, {});
|
|
30
|
+
return { em };
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log(`🚀 Server ready at ${url}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createTestContext } from "src/setupTests";
|
|
2
|
+
|
|
3
|
+
it.withCtx = (name: string, fnOrOpts: jest.itWithCtxFn | jest.ContextOpts, maybeFn?: jest.itWithCtxFn) => {
|
|
4
|
+
const fn: jest.itWithCtxFn = typeof fnOrOpts === "function" ? fnOrOpts : maybeFn!;
|
|
5
|
+
const opts: jest.ContextOpts = typeof fnOrOpts === "function" ? {} : fnOrOpts;
|
|
6
|
+
it(name, async () => fn(await createTestContext(opts)));
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
it.skip.withCtx = (name: string, fnOrOpts: jest.itWithCtxFn | jest.ContextOpts, maybeFn?: jest.itWithCtxFn) =>
|
|
10
|
+
it.skip(name, () => {});
|
|
11
|
+
it.only.withCtx = (name: string, fnOrOpts: jest.itWithCtxFn | jest.ContextOpts, maybeFn?: jest.itWithCtxFn) => {
|
|
12
|
+
const fn: jest.itWithCtxFn = typeof fnOrOpts === "function" ? fnOrOpts : maybeFn!;
|
|
13
|
+
const opts: jest.ContextOpts = typeof fnOrOpts === "function" ? {} : fnOrOpts;
|
|
14
|
+
it.only(name, async () => fn(await createTestContext(opts)));
|
|
15
|
+
};
|
|
16
|
+
xit.withCtx = it.skip.withCtx;
|
|
17
|
+
fit.withCtx = it.only.withCtx;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import expect from "expect";
|
|
2
|
+
import { newPgConnectionConfig } from "joist-orm";
|
|
3
|
+
import { PostgresDriver } from "joist-orm/pg";
|
|
4
|
+
import { toMatchEntity } from "joist-orm/tests";
|
|
5
|
+
import pg from "pg";
|
|
6
|
+
import "src/setupIt";
|
|
7
|
+
import { Context } from "./context";
|
|
8
|
+
import { EntityManager } from "./entities";
|
|
9
|
+
|
|
10
|
+
expect.extend({ toMatchEntity });
|
|
11
|
+
|
|
12
|
+
let pool: pg.Pool;
|
|
13
|
+
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
pool = new pg.Pool(newPgConnectionConfig());
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
beforeEach(async () => {
|
|
19
|
+
await pool.query("select flush_database()");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterAll(async () => {
|
|
23
|
+
await pool.end();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export function newEm(): EntityManager {
|
|
27
|
+
const driver = new PostgresDriver(pool);
|
|
28
|
+
const ctx = { pool, em: null as any } satisfies Context;
|
|
29
|
+
const em = new EntityManager(ctx, driver);
|
|
30
|
+
Object.assign(ctx, { em });
|
|
31
|
+
return em;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function createTestContext(opts: {}): Promise<Context> {
|
|
35
|
+
const em = newEm();
|
|
36
|
+
return em.ctx;
|
|
37
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"lib": ["ES2022"],
|
|
6
|
+
"moduleResolution": "nodenext",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"declarationMap": true,
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
"outDir": "./build",
|
|
15
|
+
"rootDir": "./src",
|
|
16
|
+
"baseUrl": "./src",
|
|
17
|
+
"paths": {
|
|
18
|
+
"src/*": ["./*"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"include": ["src"],
|
|
22
|
+
"exclude": ["node_modules", "build"]
|
|
23
|
+
}
|