Skip to content

Commit abf3a95

Browse files
authored
Merge branch 'main' into feat/dbauth-fetch-handler
2 parents bf2b589 + b759ad1 commit abf3a95

File tree

20 files changed

+314
-57
lines changed

20 files changed

+314
-57
lines changed

__fixtures__/example-todo-main/web/src/graphql/graphql.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type Scalars = {
1515
Int: { input: number; output: number; }
1616
Float: { input: number; output: number; }
1717
BigInt: { input: any; output: any; }
18+
Byte: { input: any; output: any; }
1819
Date: { input: any; output: any; }
1920
DateTime: { input: any; output: any; }
2021
JSON: { input: any; output: any; }

docs/docs/realtime.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ subscription CountdownFromInterval {
260260
}
261261
```
262262
263-
This example showcases how a subscription can yields its own response.
263+
This example showcases how a subscription yields its own response.
264264
265265
## Live Queries
266266

packages/api-server/src/watch.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const argv = yargs(hideBin(process.argv))
3232
description: 'Debugging port',
3333
type: 'number',
3434
})
35+
// `port` is not used when server-file is used
3536
.option('port', {
3637
alias: 'p',
3738
description: 'Port',
@@ -133,15 +134,13 @@ const buildAndRestart = async ({
133134
// Check if experimental server file exists
134135
const serverFile = resolveFile(`${rwjsPaths.api.dist}/server`)
135136
if (serverFile) {
136-
const separator = chalk.hex('#ff845e')(
137-
'------------------------------------------------------------------'
138-
)
137+
const separator = chalk.hex('#ff845e')('-'.repeat(79))
139138
console.log(
140139
[
141140
separator,
142141
`🧪 ${chalk.green('Experimental Feature')} 🧪`,
143142
separator,
144-
'Using the experimental API server file at api/dist/server.js',
143+
'Using the experimental API server file at api/dist/server.js (in watch mode)',
145144
separator,
146145
].join('\n')
147146
)

packages/cli/src/commands/__tests__/dev.test.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ jest.mock('@redwoodjs/internal/dist/dev', () => {
2525
})
2626

2727
jest.mock('@redwoodjs/project-config', () => {
28+
const actualProjectConfig = jest.requireActual('@redwoodjs/project-config')
29+
2830
return {
2931
getConfig: jest.fn(),
3032
getConfigPath: () => '/mocked/project/redwood.toml',
33+
resolveFile: actualProjectConfig.resolveFile,
3134
getPaths: () => {
3235
return {
3336
api: {
@@ -104,8 +107,8 @@ describe('yarn rw dev', () => {
104107
'yarn cross-env NODE_ENV=development rw-vite-dev'
105108
)
106109

107-
expect(apiCommand.command).toMatchInlineSnapshot(
108-
`"yarn cross-env NODE_ENV=development NODE_OPTIONS="--enable-source-maps" yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter""`
110+
expect(apiCommand.command.replace(/\s+/g, ' ')).toEqual(
111+
'yarn cross-env NODE_ENV=development NODE_OPTIONS="--enable-source-maps" yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter"'
109112
)
110113

111114
expect(generateCommand.command).toEqual('yarn rw-gen-watch')
@@ -143,8 +146,8 @@ describe('yarn rw dev', () => {
143146
'yarn cross-env NODE_ENV=development rw-dev-fe'
144147
)
145148

146-
expect(apiCommand.command).toMatchInlineSnapshot(
147-
`"yarn cross-env NODE_ENV=development NODE_OPTIONS="--enable-source-maps" yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter""`
149+
expect(apiCommand.command.replace(/\s+/g, ' ')).toEqual(
150+
'yarn cross-env NODE_ENV=development NODE_OPTIONS="--enable-source-maps" yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter"'
148151
)
149152

150153
expect(generateCommand.command).toEqual('yarn rw-gen-watch')
@@ -175,7 +178,7 @@ describe('yarn rw dev', () => {
175178

176179
const apiCommand = find(concurrentlyArgs, { name: 'api' })
177180

178-
expect(apiCommand.command).toContain(
181+
expect(apiCommand.command.replace(/\s+/g, ' ')).toContain(
179182
'yarn rw-api-server-watch --port 8911 --debug-port 90909090'
180183
)
181184
})

packages/cli/src/commands/devHandler.js

+51-23
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import fs from 'fs-extra'
55

66
import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers'
77
import { shutdownPort } from '@redwoodjs/internal/dist/dev'
8-
import { getConfig, getConfigPath } from '@redwoodjs/project-config'
8+
import {
9+
getConfig,
10+
getConfigPath,
11+
resolveFile,
12+
} from '@redwoodjs/project-config'
913
import { errorTelemetry } from '@redwoodjs/telemetry'
1014

1115
import { getPaths } from '../lib'
@@ -32,6 +36,9 @@ export const handler = async ({
3236

3337
const rwjsPaths = getPaths()
3438

39+
// Check if experimental server file exists
40+
const serverFile = resolveFile(`${rwjsPaths.api.dist}/server`)
41+
3542
// Starting values of ports from config (redwood.toml)
3643
let apiPreferredPort = parseInt(getConfig().api.port)
3744
let webPreferredPort = parseInt(getConfig().web.port)
@@ -42,8 +49,10 @@ export const handler = async ({
4249
let webAvailablePort = webPreferredPort
4350
let webPortChangeNeeded = false
4451

45-
// Check api port
46-
if (side.includes('api')) {
52+
// Check api port, unless there's a serverFile. If there is a serverFile, we
53+
// don't know what port will end up being used in the end. It's up to the
54+
// author of the server file to decide and handle that
55+
if (side.includes('api') && !serverFile) {
4756
apiAvailablePort = await getFreePort(apiPreferredPort)
4857
if (apiAvailablePort === -1) {
4958
exitWithError(undefined, {
@@ -76,17 +85,23 @@ export const handler = async ({
7685

7786
// Check for port conflict and exit with message if found
7887
if (apiPortChangeNeeded || webPortChangeNeeded) {
79-
let message = `The currently configured ports for the development server are unavailable. Suggested changes to your ports, which can be changed in redwood.toml, are:\n`
80-
message += apiPortChangeNeeded
81-
? ` - API to use port ${apiAvailablePort} instead of your currently configured ${apiPreferredPort}\n`
82-
: ``
83-
message += webPortChangeNeeded
84-
? ` - Web to use port ${webAvailablePort} instead of your currently configured ${webPreferredPort}\n`
85-
: ``
86-
message += `\nCannot run the development server until your configured ports are changed or become available.`
87-
exitWithError(undefined, {
88-
message,
89-
})
88+
const message = [
89+
'The currently configured ports for the development server are',
90+
'unavailable. Suggested changes to your ports, which can be changed in',
91+
'redwood.toml, are:\n',
92+
apiPortChangeNeeded && ` - API to use port ${apiAvailablePort} instead`,
93+
apiPortChangeNeeded && 'of your currently configured',
94+
apiPortChangeNeeded && `${apiPreferredPort}\n`,
95+
webPortChangeNeeded && ` - Web to use port ${webAvailablePort} instead`,
96+
webPortChangeNeeded && 'of your currently configured',
97+
webPortChangeNeeded && `${webPreferredPort}\n`,
98+
'\nCannot run the development server until your configured ports are',
99+
'changed or become available.',
100+
]
101+
.filter(Boolean)
102+
.join(' ')
103+
104+
exitWithError(undefined, { message })
90105
}
91106

92107
if (side.includes('api')) {
@@ -104,13 +119,17 @@ export const handler = async ({
104119
console.error(c.error(e.message))
105120
}
106121

107-
try {
108-
await shutdownPort(apiAvailablePort)
109-
} catch (e) {
110-
errorTelemetry(process.argv, `Error shutting down "api": ${e.message}`)
111-
console.error(
112-
`Error whilst shutting down "api" port: ${c.error(e.message)}`
113-
)
122+
// Again, if a server file is configured, we don't know what port it'll end
123+
// up using
124+
if (!serverFile) {
125+
try {
126+
await shutdownPort(apiAvailablePort)
127+
} catch (e) {
128+
errorTelemetry(process.argv, `Error shutting down "api": ${e.message}`)
129+
console.error(
130+
`Error whilst shutting down "api" port: ${c.error(e.message)}`
131+
)
132+
}
114133
}
115134
}
116135

@@ -142,7 +161,7 @@ export const handler = async ({
142161
return `--debug-port ${apiDebugPortInToml}`
143162
}
144163

145-
// Dont pass in debug port flag, unless configured
164+
// Don't pass in debug port flag, unless configured
146165
return ''
147166
}
148167

@@ -178,7 +197,16 @@ export const handler = async ({
178197
const jobs = {
179198
api: {
180199
name: 'api',
181-
command: `yarn cross-env NODE_ENV=development NODE_OPTIONS="${getDevNodeOptions()}" yarn nodemon --quiet --watch "${redwoodConfigPath}" --exec "yarn rw-api-server-watch --port ${apiAvailablePort} ${getApiDebugFlag()} | rw-log-formatter"`,
200+
command: [
201+
`yarn cross-env NODE_ENV=development NODE_OPTIONS="${getDevNodeOptions()}"`,
202+
' yarn nodemon',
203+
' --quiet',
204+
` --watch "${redwoodConfigPath}"`,
205+
' --exec "yarn rw-api-server-watch',
206+
` --port ${apiAvailablePort}`,
207+
` ${getApiDebugFlag()}`,
208+
' | rw-log-formatter"',
209+
].join(' '),
182210
prefixColor: 'cyan',
183211
runWhen: () => fs.existsSync(rwjsPaths.api.src),
184212
},

packages/cli/src/commands/generate/__tests__/helpers.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,10 @@ describe('mapPrismaScalarToPagePropTsType', () => {
541541
expect(helpers.mapPrismaScalarToPagePropTsType('DateTime')).toBe('string')
542542
})
543543

544+
it('maps scalar type Bytes to TS type Buffer', () => {
545+
expect(helpers.mapPrismaScalarToPagePropTsType('Bytes')).toBe('Buffer')
546+
})
547+
544548
it('maps all other type not-known to TS to unknown', () => {
545549
expect(helpers.mapPrismaScalarToPagePropTsType('Json')).toBe('unknown')
546550
})

packages/cli/src/commands/generate/helpers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export const mapRouteParamTypeToTsType = (paramType) => {
298298
return routeParamToTsType[paramType] || 'unknown'
299299
}
300300

301-
/** @type {(scalarType: 'String' | 'Boolean' | 'Int' | 'BigInt' | 'Float' | 'Decimal' | 'DateTime' ) => string } **/
301+
/** @type {(scalarType: 'String' | 'Boolean' | 'Int' | 'BigInt' | 'Float' | 'Decimal' | 'DateTime' | 'Bytes' ) => string } **/
302302
export const mapPrismaScalarToPagePropTsType = (scalarType) => {
303303
const prismaScalarToTsType = {
304304
String: 'string',
@@ -308,6 +308,7 @@ export const mapPrismaScalarToPagePropTsType = (scalarType) => {
308308
Float: 'number',
309309
Decimal: 'number',
310310
DateTime: 'string',
311+
Bytes: 'Buffer',
311312
}
312313
return prismaScalarToTsType[scalarType] || 'unknown'
313314
}

0 commit comments

Comments
 (0)