Skip to content

Commit e538ac1

Browse files
authored
new server-file (#10)
1 parent 92928a1 commit e538ac1

File tree

10 files changed

+375
-274
lines changed

10 files changed

+375
-274
lines changed

.vscode/settings.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"editor.formatOnSave": true
1010
},
1111
"cSpell.words": [
12-
"Graphi",
13-
"Graphiql",
12+
"graphiql",
1413
"headlessui",
1514
"heroicons",
1615
"opentelemetry",

__fixtures__/test-project/api/package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
"@opentelemetry/semantic-conventions": "^1.17.1",
1414
"@prisma/instrumentation": "^5.4.2",
1515
"@react-email/components": "^0.0.12",
16-
"@redwoodjs/api": "7.0.0-canary.785",
17-
"@redwoodjs/auth-dbauth-api": "7.0.0-canary.785",
18-
"@redwoodjs/graphql-server": "7.0.0-canary.785",
19-
"@redwoodjs/mailer-core": "7.0.0-canary.785",
20-
"@redwoodjs/mailer-handler-nodemailer": "7.0.0-canary.785",
21-
"@redwoodjs/mailer-renderer-react-email": "7.0.0-canary.785"
16+
"@redwoodjs/api": "7.0.0-canary.874",
17+
"@redwoodjs/auth-dbauth-api": "7.0.0-canary.874",
18+
"@redwoodjs/graphql-server": "7.0.0-canary.874",
19+
"@redwoodjs/mailer-core": "7.0.0-canary.874",
20+
"@redwoodjs/mailer-handler-nodemailer": "7.0.0-canary.874",
21+
"@redwoodjs/mailer-renderer-react-email": "7.0.0-canary.874"
2222
},
2323
"devDependencies": {
24-
"@redwoodjs/mailer-handler-in-memory": "7.0.0-canary.785",
25-
"@redwoodjs/mailer-handler-studio": "7.0.0-canary.785"
24+
"@redwoodjs/mailer-handler-in-memory": "7.0.0-canary.874",
25+
"@redwoodjs/mailer-handler-studio": "7.0.0-canary.874"
2626
}
2727
}

__fixtures__/test-project/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
]
88
},
99
"devDependencies": {
10-
"@redwoodjs/core": "7.0.0-canary.785",
11-
"@redwoodjs/studio": "7.0.0-canary.785"
10+
"@redwoodjs/core": "7.0.0-canary.874",
11+
"@redwoodjs/studio": "7.0.0-canary.874"
1212
},
1313
"eslintConfig": {
1414
"extends": "@redwoodjs/eslint-config",
@@ -28,6 +28,6 @@
2828
"studio:start": "yarn rw-studio | yarn rw-log-formatter"
2929
},
3030
"dependencies": {
31-
"@redwoodjs/realtime": "7.0.0-canary.785"
31+
"@redwoodjs/realtime": "7.0.0-canary.874"
3232
}
3333
}

__fixtures__/test-project/web/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
]
1212
},
1313
"dependencies": {
14-
"@redwoodjs/auth-dbauth-web": "7.0.0-canary.785",
15-
"@redwoodjs/forms": "7.0.0-canary.785",
16-
"@redwoodjs/router": "7.0.0-canary.785",
17-
"@redwoodjs/web": "7.0.0-canary.785",
14+
"@redwoodjs/auth-dbauth-web": "7.0.0-canary.874",
15+
"@redwoodjs/forms": "7.0.0-canary.874",
16+
"@redwoodjs/router": "7.0.0-canary.874",
17+
"@redwoodjs/web": "7.0.0-canary.874",
1818
"humanize-string": "2.1.0",
1919
"react": "0.0.0-experimental-e5205658f-20230913",
2020
"react-dom": "0.0.0-experimental-e5205658f-20230913"
2121
},
2222
"devDependencies": {
23-
"@redwoodjs/vite": "7.0.0-canary.785",
23+
"@redwoodjs/vite": "7.0.0-canary.874",
2424
"@types/react": "18.2.37",
2525
"@types/react-dom": "18.2.15",
2626
"autoprefixer": "^10.4.16",

api/package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
"@babel/types": "7.22.17",
99
"@graphql-inspector/core": "5.0.1",
1010
"@prisma/internals": "5.2.0",
11-
"@redwoodjs/api": "7.0.0-canary.785",
12-
"@redwoodjs/auth-dbauth-api": "7.0.0-canary.785",
13-
"@redwoodjs/fastify": "7.0.0-canary.785",
14-
"@redwoodjs/graphql-server": "7.0.0-canary.785",
15-
"@redwoodjs/project-config": "7.0.0-canary.785",
16-
"@redwoodjs/realtime": "7.0.0-canary.785",
11+
"@redwoodjs/api": "7.0.0-canary.874",
12+
"@redwoodjs/api-server": "7.0.0-canary.874",
13+
"@redwoodjs/auth-dbauth-api": "7.0.0-canary.874",
14+
"@redwoodjs/fastify": "7.0.0-canary.874",
15+
"@redwoodjs/graphql-server": "7.0.0-canary.874",
16+
"@redwoodjs/project-config": "7.0.0-canary.874",
17+
"@redwoodjs/realtime": "7.0.0-canary.874",
1718
"better-sqlite3": "8.6.0",
1819
"chalk": "4.1.2",
1920
"chokidar": "3.5.3",

api/src/functions/graphql.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { createGraphQLHandler } from '@redwoodjs/graphql-server'
2+
3+
import directives from 'src/directives/**/*.{js,ts}'
4+
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
5+
import services from 'src/services/**/*.{js,ts}'
6+
7+
import { db } from 'src/lib/db'
8+
import { logger } from 'src/lib/logger'
9+
import { realtime } from 'src/lib/realtime'
10+
11+
export const handler = createGraphQLHandler({
12+
loggerConfig: {
13+
logger: logger,
14+
},
15+
sdls,
16+
services,
17+
directives,
18+
allowIntrospection: true,
19+
allowGraphiQL: true,
20+
realtime,
21+
onException: () => {
22+
// Disconnect from your database with an unhandled exception.
23+
db.$disconnect()
24+
},
25+
})

api/src/server.ts

+10-38
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,13 @@ import path from 'node:path'
44
import chalk from 'chalk'
55
import { config } from 'dotenv-defaults'
66
import execa from 'execa'
7-
import Fastify from 'fastify'
87
import open from 'open'
98
import { SMTPServer } from 'smtp-server'
109

11-
import {
12-
coerceRootPath,
13-
redwoodFastifyWeb,
14-
redwoodFastifyAPI,
15-
redwoodFastifyGraphQLServer,
16-
DEFAULT_REDWOOD_FASTIFY_CONFIG,
17-
} from '@redwoodjs/fastify'
18-
19-
import directives from 'src/directives/**/*.{js,ts}'
20-
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
21-
import services from 'src/services/**/*.{js,ts}'
10+
import { createServer } from '@redwoodjs/api-server'
11+
import { coerceRootPath, redwoodFastifyWeb } from '@redwoodjs/fastify'
2212

2313
import { logger } from 'src/lib/logger'
24-
import { realtime } from 'src/lib/realtime'
2514

2615
import { startConnectionWatching } from './util/connectionWatching'
2716
import { startWatchers } from './util/fsWatching'
@@ -93,32 +82,15 @@ export async function serve(
9382

9483
rewriteApiPortEnvVar(apiPort)
9584

96-
const fastify = Fastify(DEFAULT_REDWOOD_FASTIFY_CONFIG)
85+
const server = await createServer({
86+
apiRootPath,
87+
})
9788

9889
if (enableWeb) {
99-
await fastify.register(redwoodFastifyWeb)
90+
await server.register(redwoodFastifyWeb)
10091
}
10192

102-
await fastify.register(redwoodFastifyAPI, {
103-
redwood: {
104-
apiRootPath,
105-
},
106-
})
107-
108-
await fastify.register(redwoodFastifyGraphQLServer, {
109-
loggerConfig: {
110-
logger: logger,
111-
},
112-
graphiQLEndpoint: enableWeb ? '/.redwood/functions/graphql' : '/graphql',
113-
sdls,
114-
services,
115-
directives,
116-
allowIntrospection: true,
117-
allowGraphiQL: true,
118-
realtime,
119-
})
120-
121-
await fastify.register(graphqlProxy)
93+
await server.register(graphqlProxy)
12294

12395
// Start filesystem watchers
12496
await startWatchers()
@@ -138,8 +110,8 @@ export async function serve(
138110
})
139111

140112
// Start
141-
fastify.listen({ port: apiPort })
142-
fastify.ready(() => {
113+
server.listen({ port: apiPort })
114+
server.ready(() => {
143115
logger.info('Studio is up and running!')
144116
logger.info(
145117
`To access the Studio, visit ${chalk.green(
@@ -154,7 +126,7 @@ export async function serve(
154126

155127
// Cleanup (async will not be resolved!)
156128
process.on('exit', () => {
157-
fastify.close()
129+
server.close()
158130
})
159131
}
160132

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
]
99
},
1010
"devDependencies": {
11-
"@redwoodjs/cli-storybook": "7.0.0-canary.785",
12-
"@redwoodjs/core": "7.0.0-canary.785",
11+
"@redwoodjs/cli-storybook": "7.0.0-canary.874",
12+
"@redwoodjs/core": "7.0.0-canary.874",
1313
"chalk": "4.1.2",
1414
"execa": "5.1.1",
1515
"fs-extra": "11.1.1",

web/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"@heroicons/react": "2.1.1",
1818
"@nivo/core": "^0.84.0",
1919
"@nivo/treemap": "^0.84.0",
20-
"@redwoodjs/forms": "7.0.0-canary.785",
21-
"@redwoodjs/router": "7.0.0-canary.785",
22-
"@redwoodjs/web": "7.0.0-canary.785",
20+
"@redwoodjs/forms": "7.0.0-canary.874",
21+
"@redwoodjs/router": "7.0.0-canary.874",
22+
"@redwoodjs/web": "7.0.0-canary.874",
2323
"@tremor/react": "3.13.2",
2424
"buffer": "6.0.3",
2525
"date-fns": "^3.2.0",
@@ -32,7 +32,7 @@
3232
"use-url-search-params": "2.5.1"
3333
},
3434
"devDependencies": {
35-
"@redwoodjs/vite": "7.0.0-canary.785",
35+
"@redwoodjs/vite": "7.0.0-canary.874",
3636
"@types/react": "18.2.37",
3737
"@types/react-dom": "18.2.15",
3838
"autoprefixer": "10.4.15",

0 commit comments

Comments
 (0)