create-joist-app 0.0.1
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/create-app.d.ts +18 -0
- package/build/create-app.d.ts.map +1 -0
- package/build/create-app.js +73 -0
- package/build/create-app.js.map +1 -0
- package/build/create-app.test.d.ts +2 -0
- package/build/create-app.test.d.ts.map +1 -0
- package/build/create-app.test.js +176 -0
- package/build/create-app.test.js.map +1 -0
- package/build/create-db-dockerfile.d.ts +2 -0
- package/build/create-db-dockerfile.d.ts.map +1 -0
- package/build/create-db-dockerfile.js +43 -0
- package/build/create-db-dockerfile.js.map +1 -0
- package/build/create-docker-compose.d.ts +3 -0
- package/build/create-docker-compose.d.ts.map +1 -0
- package/build/create-docker-compose.js +35 -0
- package/build/create-docker-compose.js.map +1 -0
- package/build/create-env.d.ts +3 -0
- package/build/create-env.d.ts.map +1 -0
- package/build/create-env.js +16 -0
- package/build/create-env.js.map +1 -0
- package/build/helpers/copy.d.ts +3 -0
- package/build/helpers/copy.d.ts.map +1 -0
- package/build/helpers/copy.js +33 -0
- package/build/helpers/copy.js.map +1 -0
- package/build/helpers/get-package-manager.d.ts +3 -0
- package/build/helpers/get-package-manager.d.ts.map +1 -0
- package/build/helpers/get-package-manager.js +17 -0
- package/build/helpers/get-package-manager.js.map +1 -0
- package/build/helpers/install.d.ts +3 -0
- package/build/helpers/install.d.ts.map +1 -0
- package/build/helpers/install.js +29 -0
- package/build/helpers/install.js.map +1 -0
- package/build/helpers/is-folder-empty.d.ts +2 -0
- package/build/helpers/is-folder-empty.d.ts.map +1 -0
- package/build/helpers/is-folder-empty.js +14 -0
- package/build/helpers/is-folder-empty.js.map +1 -0
- package/build/helpers/is-folder-empty.test.d.ts +2 -0
- package/build/helpers/is-folder-empty.test.d.ts.map +1 -0
- package/build/helpers/is-folder-empty.test.js +38 -0
- package/build/helpers/is-folder-empty.test.js.map +1 -0
- package/build/helpers/is-writeable.d.ts +2 -0
- package/build/helpers/is-writeable.d.ts.map +1 -0
- package/build/helpers/is-writeable.js +17 -0
- package/build/helpers/is-writeable.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +213 -0
- package/build/index.js.map +1 -0
- package/build/replace-sentinels.d.ts +2 -0
- package/build/replace-sentinels.d.ts.map +1 -0
- package/build/replace-sentinels.js +59 -0
- package/build/replace-sentinels.js.map +1 -0
- package/build/update-package-json.d.ts +2 -0
- package/build/update-package-json.d.ts.map +1 -0
- package/build/update-package-json.js +25 -0
- package/build/update-package-json.js.map +1 -0
- package/package.json +55 -0
- 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,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
|
+
}
|