create-joist-app 1.0.4 → 1.0.6
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-joist-app",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Create a new Joist ORM project with a single command",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"format": "prettier --write 'src/**/*.{ts,js}'"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"commander": "^
|
|
34
|
+
"commander": "^14.0.3",
|
|
35
35
|
"picocolors": "^1.1.1",
|
|
36
36
|
"prompts": "^2.4.2",
|
|
37
37
|
"validate-npm-package-name": "^6.0.2"
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
"typescript": "5.9.3"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
|
-
"node": ">=
|
|
53
|
+
"node": ">=22.0.0"
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { newPgConnectionConfig } from "joist-orm";
|
|
2
2
|
import { PostgresDriver } from "joist-orm/pg";
|
|
3
3
|
import { Pool } from "pg";
|
|
4
|
+
import type { EntityManager } from "./entities";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
/** The app-wide global context, created once on boot & shared across all requests. */
|
|
7
|
+
export interface AppContext {
|
|
6
8
|
pool: Pool;
|
|
9
|
+
driver: PostgresDriver;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The request-specific context, created once per request. */
|
|
13
|
+
export interface RequestContext extends AppContext {
|
|
7
14
|
em: EntityManager;
|
|
8
15
|
}
|
|
9
16
|
|
|
10
|
-
export
|
|
17
|
+
export type Context = RequestContext;
|
|
18
|
+
|
|
19
|
+
export function newAppContext(): AppContext {
|
|
11
20
|
const pool = new Pool(newPgConnectionConfig());
|
|
12
|
-
const
|
|
13
|
-
return {
|
|
21
|
+
const driver = new PostgresDriver(pool);
|
|
22
|
+
return { pool, driver };
|
|
14
23
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { ApolloServer } from "@apollo/server";
|
|
2
2
|
import { startStandaloneServer } from "@apollo/server/standalone";
|
|
3
|
-
import { loadSchemaSync } from "@graphql-tools/load";
|
|
4
3
|
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
|
|
5
|
-
import {
|
|
6
|
-
import { newPgConnectionConfig } from "joist-orm/pg";
|
|
7
|
-
import knex from "knex";
|
|
4
|
+
import { loadSchemaSync } from "@graphql-tools/load";
|
|
8
5
|
import path from "path";
|
|
9
|
-
import { Context } from "./context";
|
|
10
|
-
import {
|
|
6
|
+
import { Context, newAppContext } from "./context";
|
|
7
|
+
import { EntityManager } from "./entities";
|
|
11
8
|
import { resolvers } from "./resolvers";
|
|
12
9
|
|
|
13
10
|
const typeDefs = loadSchemaSync(path.join(__dirname, "./**/*.graphql"), {
|
|
@@ -15,22 +12,17 @@ const typeDefs = loadSchemaSync(path.join(__dirname, "./**/*.graphql"), {
|
|
|
15
12
|
});
|
|
16
13
|
|
|
17
14
|
async function main() {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const server = new ApolloServer<Context>({
|
|
22
|
-
typeDefs,
|
|
23
|
-
resolvers,
|
|
24
|
-
});
|
|
25
|
-
|
|
15
|
+
const appContext = newAppContext();
|
|
16
|
+
const server = new ApolloServer<Context>({ typeDefs, resolvers });
|
|
26
17
|
const { url } = await startStandaloneServer(server, {
|
|
27
18
|
listen: { port: parseInt(process.env.PORT || "4000") },
|
|
28
19
|
context: async () => {
|
|
29
|
-
const
|
|
30
|
-
|
|
20
|
+
const ctx = { ...appContext, em: null as any } satisfies Context;
|
|
21
|
+
const em = new EntityManager(ctx, appContext.driver);
|
|
22
|
+
Object.assign(ctx, { em });
|
|
23
|
+
return ctx;
|
|
31
24
|
},
|
|
32
25
|
});
|
|
33
|
-
|
|
34
26
|
console.log(`🚀 Server ready at ${url}`);
|
|
35
27
|
}
|
|
36
28
|
|
|
@@ -25,7 +25,7 @@ afterAll(async () => {
|
|
|
25
25
|
|
|
26
26
|
export function newEm(): EntityManager {
|
|
27
27
|
const driver = new PostgresDriver(pool);
|
|
28
|
-
const ctx = { pool, em: null as any } satisfies Context;
|
|
28
|
+
const ctx = { pool, driver, em: null as any } satisfies Context;
|
|
29
29
|
const em = new EntityManager(ctx, driver);
|
|
30
30
|
Object.assign(ctx, { em });
|
|
31
31
|
return em;
|