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.
Files changed (119) hide show
  1. package/build/create-app.d.ts +18 -0
  2. package/build/create-app.d.ts.map +1 -0
  3. package/build/create-app.js +73 -0
  4. package/build/create-app.js.map +1 -0
  5. package/build/create-app.test.d.ts +2 -0
  6. package/build/create-app.test.d.ts.map +1 -0
  7. package/build/create-app.test.js +176 -0
  8. package/build/create-app.test.js.map +1 -0
  9. package/build/create-db-dockerfile.d.ts +2 -0
  10. package/build/create-db-dockerfile.d.ts.map +1 -0
  11. package/build/create-db-dockerfile.js +43 -0
  12. package/build/create-db-dockerfile.js.map +1 -0
  13. package/build/create-docker-compose.d.ts +3 -0
  14. package/build/create-docker-compose.d.ts.map +1 -0
  15. package/build/create-docker-compose.js +35 -0
  16. package/build/create-docker-compose.js.map +1 -0
  17. package/build/create-env.d.ts +3 -0
  18. package/build/create-env.d.ts.map +1 -0
  19. package/build/create-env.js +16 -0
  20. package/build/create-env.js.map +1 -0
  21. package/build/helpers/copy.d.ts +3 -0
  22. package/build/helpers/copy.d.ts.map +1 -0
  23. package/build/helpers/copy.js +33 -0
  24. package/build/helpers/copy.js.map +1 -0
  25. package/build/helpers/get-package-manager.d.ts +3 -0
  26. package/build/helpers/get-package-manager.d.ts.map +1 -0
  27. package/build/helpers/get-package-manager.js +17 -0
  28. package/build/helpers/get-package-manager.js.map +1 -0
  29. package/build/helpers/install.d.ts +3 -0
  30. package/build/helpers/install.d.ts.map +1 -0
  31. package/build/helpers/install.js +29 -0
  32. package/build/helpers/install.js.map +1 -0
  33. package/build/helpers/is-folder-empty.d.ts +2 -0
  34. package/build/helpers/is-folder-empty.d.ts.map +1 -0
  35. package/build/helpers/is-folder-empty.js +14 -0
  36. package/build/helpers/is-folder-empty.js.map +1 -0
  37. package/build/helpers/is-folder-empty.test.d.ts +2 -0
  38. package/build/helpers/is-folder-empty.test.d.ts.map +1 -0
  39. package/build/helpers/is-folder-empty.test.js +38 -0
  40. package/build/helpers/is-folder-empty.test.js.map +1 -0
  41. package/build/helpers/is-writeable.d.ts +2 -0
  42. package/build/helpers/is-writeable.d.ts.map +1 -0
  43. package/build/helpers/is-writeable.js +17 -0
  44. package/build/helpers/is-writeable.js.map +1 -0
  45. package/build/index.d.ts +3 -0
  46. package/build/index.d.ts.map +1 -0
  47. package/build/index.js +213 -0
  48. package/build/index.js.map +1 -0
  49. package/build/replace-sentinels.d.ts +2 -0
  50. package/build/replace-sentinels.d.ts.map +1 -0
  51. package/build/replace-sentinels.js +59 -0
  52. package/build/replace-sentinels.js.map +1 -0
  53. package/build/update-package-json.d.ts +2 -0
  54. package/build/update-package-json.d.ts.map +1 -0
  55. package/build/update-package-json.js +25 -0
  56. package/build/update-package-json.js.map +1 -0
  57. package/package.json +55 -0
  58. package/templates/basic/README.md +70 -0
  59. package/templates/basic/gitignore +28 -0
  60. package/templates/basic/jest.config.js +14 -0
  61. package/templates/basic/joist-config.json +7 -0
  62. package/templates/basic/migrations/1580658856631_initial.ts +22 -0
  63. package/templates/basic/package.json +28 -0
  64. package/templates/basic/src/context.ts +14 -0
  65. package/templates/basic/src/entities/Author.test.ts +17 -0
  66. package/templates/basic/src/entities/Author.ts +7 -0
  67. package/templates/basic/src/entities/Book.ts +3 -0
  68. package/templates/basic/src/entities/entities.ts +14 -0
  69. package/templates/basic/src/entities/factories/index.ts +2 -0
  70. package/templates/basic/src/entities/factories/newAuthor.ts +6 -0
  71. package/templates/basic/src/entities/factories/newBook.ts +6 -0
  72. package/templates/basic/src/entities/index.ts +3 -0
  73. package/templates/basic/src/setupTestEnv.ts +5 -0
  74. package/templates/basic/src/setupTests.ts +29 -0
  75. package/templates/basic/tsconfig.json +23 -0
  76. package/templates/graphql/README.md +84 -0
  77. package/templates/graphql/codegen.yml +11 -0
  78. package/templates/graphql/gitignore +28 -0
  79. package/templates/graphql/graphql-codegen-joist.js +5 -0
  80. package/templates/graphql/graphql-codegen.js +26 -0
  81. package/templates/graphql/jest.config.js +14 -0
  82. package/templates/graphql/joist-config.json +8 -0
  83. package/templates/graphql/migrations/1580658856631_initial.ts +38 -0
  84. package/templates/graphql/package.json +41 -0
  85. package/templates/graphql/schema/.history.json +9 -0
  86. package/templates/graphql/schema/author.graphql +20 -0
  87. package/templates/graphql/schema/book.graphql +19 -0
  88. package/templates/graphql/schema/enums.graphql +0 -0
  89. package/templates/graphql/schema/root.graphql +0 -0
  90. package/templates/graphql/src/.history.json +12 -0
  91. package/templates/graphql/src/context.ts +14 -0
  92. package/templates/graphql/src/entities/Author.test.ts +36 -0
  93. package/templates/graphql/src/entities/Author.ts +7 -0
  94. package/templates/graphql/src/entities/Book.ts +3 -0
  95. package/templates/graphql/src/entities/entities.ts +14 -0
  96. package/templates/graphql/src/entities/factories/index.ts +2 -0
  97. package/templates/graphql/src/entities/factories/newAuthor.ts +6 -0
  98. package/templates/graphql/src/entities/factories/newBook.ts +6 -0
  99. package/templates/graphql/src/entities/index.ts +3 -0
  100. package/templates/graphql/src/jest.d.ts +9 -0
  101. package/templates/graphql/src/resolvers/author/authorResolvers.test.ts +17 -0
  102. package/templates/graphql/src/resolvers/author/authorResolvers.ts +5 -0
  103. package/templates/graphql/src/resolvers/author/saveAuthorMutation.test.ts +13 -0
  104. package/templates/graphql/src/resolvers/author/saveAuthorMutation.ts +9 -0
  105. package/templates/graphql/src/resolvers/book/bookResolvers.test.ts +17 -0
  106. package/templates/graphql/src/resolvers/book/bookResolvers.ts +5 -0
  107. package/templates/graphql/src/resolvers/book/saveBookMutation.test.ts +16 -0
  108. package/templates/graphql/src/resolvers/book/saveBookMutation.ts +9 -0
  109. package/templates/graphql/src/resolvers/enumResolvers.ts +5 -0
  110. package/templates/graphql/src/resolvers/index.ts +15 -0
  111. package/templates/graphql/src/resolvers/mutations/index.ts +7 -0
  112. package/templates/graphql/src/resolvers/objects/index.ts +6 -0
  113. package/templates/graphql/src/resolvers/testUtils.ts +10 -0
  114. package/templates/graphql/src/resolvers/utils.ts +1 -0
  115. package/templates/graphql/src/server.ts +37 -0
  116. package/templates/graphql/src/setupIt.ts +17 -0
  117. package/templates/graphql/src/setupTestEnv.ts +5 -0
  118. package/templates/graphql/src/setupTests.ts +37 -0
  119. 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,5 @@
1
+ import { Book } from "src/entities";
2
+ import type { BookResolvers } from "src/generated/graphql-types";
3
+ import { entityResolver } from "src/resolvers/utils";
4
+
5
+ export const bookResolvers: BookResolvers = { ...entityResolver(Book) };
@@ -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,5 @@
1
+ import type { Resolvers } from "src/generated/graphql-types";
2
+
3
+ type EnumDetails = never;
4
+
5
+ export const enumResolvers: Pick<Resolvers, EnumDetails> = {};
@@ -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,6 @@
1
+ import { authorResolvers } from "src/resolvers/author/authorResolvers";
2
+ import { bookResolvers } from "src/resolvers/book/bookResolvers";
3
+
4
+ // This file is auto-generated
5
+
6
+ export const objectResolvers = { Author: authorResolvers, Book: bookResolvers };
@@ -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,5 @@
1
+ import { GetEnvVars } from "env-cmd";
2
+
3
+ export default async function globalSetup() {
4
+ Object.entries(await GetEnvVars()).forEach(([key, value]) => (process.env[key] = value));
5
+ }
@@ -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
+ }