Skip to content

Commit 2e82513

Browse files
committed
Merge branch 'main' of github.com:redwoodjs/redwood into feat/api-skip-prebuild-try-2
* 'main' of github.com:redwoodjs/redwood: Fastify config: Use exact file extension in log message (redwoodjs#9828) Remove unused Fastify plugin (redwoodjs#9827) Add trusted-documents to fragments CI smoke-test (redwoodjs#9826) prerender: Enable Trusted Documents support (redwoodjs#9825) trustedDocuments.test.ts: Format source cli: add missing dep jscodeshift (redwoodjs#9823) graphql setup fragments: Move telemetry to main handler (redwoodjs#9819) feat: Adds Setup CLI Command to Configure GraphQL Trusted Documents (redwoodjs#9800) Update cli tsconfig to reference used packages (redwoodjs#9822) fragments setup: newline fix + refactor->rename (redwoodjs#9821) yarn rw setup graphql fragments (redwoodjs#9811)
2 parents 2fd6b9a + 597e673 commit 2e82513

File tree

71 files changed

+3341
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3341
-54
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = {
2727
'packages/babel-config/src/__tests__/__fixtures__/**/*',
2828
'packages/core/**/__fixtures__/**/*',
2929
'packages/codemods/**/__testfixtures__/**/*',
30+
'packages/cli/**/__testfixtures__/**/*',
3031
'packages/core/config/storybook/**/*',
3132
'packages/studio/dist-*/**/*',
3233
],

.github/workflows/ci.yml

+12
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,18 @@ jobs:
780780
REDWOOD_TEST_PROJECT_PATH: '${{ steps.set-up-test-project.outputs.test-project-path }}'
781781
REDWOOD_DISABLE_TELEMETRY: 1
782782

783+
- name: Enable trusted-documents in Fragments test project
784+
run: npx -y tsx ./tasks/test-project/set-up-trusted-documents ${{ steps.set-up-test-project.outputs.test-project-path }}
785+
env:
786+
REDWOOD_DISABLE_TELEMETRY: 1
787+
788+
- name: 📄 Run prerender smoke tests against Fragments test project (with trusted-documents enabled)
789+
working-directory: tasks/smoke-tests/prerender
790+
run: npx playwright test
791+
env:
792+
REDWOOD_TEST_PROJECT_PATH: ${{ steps.set-up-test-project.outputs.test-project-path }}
793+
REDWOOD_DISABLE_TELEMETRY: 1
794+
783795
fragments-smoke-tests-skip:
784796
needs: detect-changes
785797

docs/docs/cli-commands.md

+66-1
Original file line numberDiff line numberDiff line change
@@ -1999,11 +1999,76 @@ We perform a simple compatibility check in an attempt to make you aware of poten
19991999
20002000
It's the author of the npm package's responsibility to specify the correct compatibility range, so **you should always research the packages you use with this command**. Especially since they will be executing code on your machine!
20012001
2002+
### setup graphql
2003+
2004+
This command creates the necessary files to support GraphQL features like fragments and trusted documents.
2005+
2006+
#### Usage
2007+
2008+
Run `yarn rw setup graphql <feature>`
2009+
2010+
#### setup graphql fragments
2011+
2012+
This command creates the necessary configuration to start using [GraphQL Fragments](./graphql/fragments.md).
2013+
2014+
```
2015+
yarn redwood setup graphql fragments
2016+
```
2017+
2018+
| Arguments & Options | Description |
2019+
| :------------------ | :--------------------------------------- |
2020+
| `--force, -f` | Overwrite existing files and skip checks |
2021+
2022+
#### Usage
2023+
2024+
Run `yarn rw setup graphql fragments`
2025+
2026+
#### Example
2027+
2028+
```bash
2029+
~/redwood-app$ yarn rw setup graphql fragments
2030+
✔ Update Redwood Project Configuration to enable GraphQL Fragments
2031+
✔ Generate possibleTypes.ts
2032+
✔ Import possibleTypes in App.tsx
2033+
✔ Add possibleTypes to the GraphQL cache config
2034+
```
2035+
2036+
#### setup graphql trusted-documents
2037+
2038+
This command creates the necessary configuration to start using [GraphQL Trusted Documents](./graphql/trusted-documents.md).
2039+
2040+
2041+
```
2042+
yarn redwood setup graphql trusted-documents
2043+
```
2044+
2045+
#### Usage
2046+
2047+
Run `yarn rw setup graphql trusted-documents`
2048+
2049+
#### Example
2050+
2051+
```bash
2052+
~/redwood-app$ yarn rw setup graphql trusted-documents
2053+
✔ Update Redwood Project Configuration to enable GraphQL Trusted Documents ...
2054+
✔ Generating Trusted Documents store ...
2055+
✔ Configuring the GraphQL Handler to use a Trusted Documents store ...
2056+
```
2057+
2058+
2059+
If you have not setup the RedwoodJS server file, it will be setup:
2060+
2061+
```bash
2062+
✔ Adding the experimental server file...
2063+
✔ Adding config to redwood.toml...
2064+
✔ Adding required api packages...
2065+
```
2066+
2067+
20022068
### setup realtime
20032069
20042070
This command creates the necessary files, installs the required packages, and provides examples to setup RedwoodJS Realtime from GraphQL live queries and subscriptions. See the Realtime docs for more information.
20052071
2006-
20072072
```
20082073
yarn redwood setup realtime
20092074
```

docs/docs/graphql/fragments.md

+18-10
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ With `registerFragment`, you can register a fragment with the registry and get b
8383

8484
which can then be used to work with the registered fragment.
8585

86+
### Setup
87+
88+
`yarn rw setup graphql fragments`
89+
90+
See more in [cli commands - setup graphql fragments](../cli-commands.md#setup-graphql-fragments).
91+
8692
### registerFragment
8793

8894
To register a fragment, you can simply register it with `registerFragment`.
@@ -200,7 +206,7 @@ the `getCacheKey` is a function where `getCacheKey(42)` would return `Book:42`.
200206
import { registerFragment } from '@redwoodjs/web/apollo'
201207
202208
const { useRegisteredFragment } = registerFragment(
203-
...
209+
// ...
204210
)
205211
```
206212

@@ -281,17 +287,19 @@ To make this easier to maintain, RedwoodJS GraphQL CodeGen automatically generat
281287

282288

283289
```ts
290+
// web/src/App.tsx
291+
284292
import possibleTypes from 'src/graphql/possibleTypes'
285293

286-
...
287-
/// web/src/App.tsx
288-
<RedwoodApolloProvider
289-
graphQLClientConfig={{
290-
cacheConfig: {
291-
...possibleTypes,
292-
},
293-
}}
294-
>
294+
// ...
295+
296+
const graphQLClientConfig = {
297+
cacheConfig: {
298+
...possibleTypes,
299+
},
300+
}
301+
302+
<RedwoodApolloProvider graphQLClientConfig={graphQLClientConfig}>
295303
```
296304

297305
To generate the `src/graphql/possibleTypes` file, enable fragments in `redwood.toml`:

docs/docs/graphql/trusted-documents.md

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ Thus preventing unwanted queries or GraphQl traversal attacks,
9393

9494
## Configure Trusted Documents
9595

96+
Below are instructions to manually configure Trusted Documents in your RedwoodJS project.
97+
98+
Alternatively, you can use the `yarn redwood setup graphql trusted-documents` [CLI setup command](../cli-commands.md#setup-graphql-trusted-docs).
99+
100+
96101
### Configure redwood.toml
97102

98103
Setting `trustedDocuments` to true will

packages/cli-helpers/src/lib/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,17 @@ export const transformTSToJS = (filename: string, content: string) => {
5454
*/
5555
export const prettierOptions = () => {
5656
try {
57-
return require(path.join(getPaths().base, 'prettier.config.js'))
57+
const options = require(path.join(getPaths().base, 'prettier.config.js'))
58+
59+
if (options.tailwindConfig?.startsWith('.')) {
60+
// Make this work with --cwd
61+
options.tailwindConfig = path.join(
62+
process.env.RWJS_CWD ?? process.cwd(),
63+
options.tailwindConfig
64+
)
65+
}
66+
67+
return options
5868
} catch (e) {
5969
return undefined
6070
}

packages/cli/jest.config.js

-9
This file was deleted.

packages/cli/jest.config.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { Config } from 'jest'
2+
3+
const config: Config = {
4+
projects: [
5+
{
6+
displayName: 'root',
7+
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/*.test.[jt]s?(x)'],
8+
testPathIgnorePatterns: [
9+
'__fixtures__',
10+
'__testfixtures__',
11+
'__codemod_tests__',
12+
'__tests__/utils/*',
13+
'__tests__/fixtures/*',
14+
'.d.ts',
15+
'dist',
16+
],
17+
moduleNameMapper: {
18+
'^src/(.*)': '<rootDir>/src/$1',
19+
},
20+
setupFilesAfterEnv: ['./jest.setup.js'],
21+
},
22+
{
23+
displayName: 'setup codemods',
24+
testMatch: ['**/commands/setup/**/__codemod_tests__/*.ts'],
25+
testPathIgnorePatterns: [
26+
'__fixtures__',
27+
'__testfixtures__',
28+
'__tests__/utils/*',
29+
'__tests__/fixtures/*',
30+
'.d.ts',
31+
'dist',
32+
],
33+
setupFilesAfterEnv: ['./src/jest.codemods.setup.ts'],
34+
},
35+
],
36+
testTimeout: 20_000,
37+
}
38+
39+
export default config

packages/cli/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"scripts": {
2020
"build": "yarn build:js",
2121
"build:clean-dist": "rimraf 'dist/**/*/__tests__' --glob",
22-
"build:js": "babel src -d dist --extensions \".js,.jsx,.ts,.tsx\" --copy-files --no-copy-ignored && yarn build:clean-dist",
22+
"build:js": "babel src -d dist --extensions \".js,.jsx,.ts,.tsx\" --ignore \"src/**/__tests__/**\" --ignore \"src/**/__testfixtures__/**\" --copy-files --no-copy-ignored && yarn build:clean-dist",
2323
"build:pack": "yarn pack -o redwoodjs-cli.tgz",
2424
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build && yarn fix:permissions\"",
2525
"dev": "RWJS_CWD=../../__fixtures__/example-todo-main node dist/index.js",
@@ -63,6 +63,7 @@
6363
"fast-glob": "3.3.2",
6464
"fs-extra": "11.2.0",
6565
"humanize-string": "2.1.0",
66+
"jscodeshift": "0.15.0",
6667
"latest-version": "5.1.0",
6768
"listr2": "6.6.1",
6869
"lodash": "4.17.21",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
4+
import { findUp } from '@redwoodjs/project-config'
5+
6+
describe('fragments graphQLClientConfig', () => {
7+
test('App.tsx with no graphQLClientConfig', async () => {
8+
await matchFolderTransform('appGqlConfigTransform', 'config-simple', {
9+
useJsCodeshift: true,
10+
})
11+
})
12+
13+
test('App.tsx with existing inline graphQLClientConfig', async () => {
14+
await matchFolderTransform('appGqlConfigTransform', 'existingPropInline', {
15+
useJsCodeshift: true,
16+
})
17+
})
18+
19+
test('App.tsx with existing graphQLClientConfig in separate variable', async () => {
20+
await matchFolderTransform(
21+
'appGqlConfigTransform',
22+
'existingPropVariable',
23+
{
24+
useJsCodeshift: true,
25+
}
26+
)
27+
})
28+
29+
test('App.tsx with existing graphQLClientConfig in separate variable, without cacheConfig property', async () => {
30+
await matchFolderTransform(
31+
'appGqlConfigTransform',
32+
'existingPropVariableNoCacheConfig',
33+
{
34+
useJsCodeshift: true,
35+
}
36+
)
37+
})
38+
39+
test('App.tsx with existing graphQLClientConfig in separate variable with non-standard name', async () => {
40+
await matchFolderTransform(
41+
'appGqlConfigTransform',
42+
'existingPropVariableCustomName',
43+
{
44+
useJsCodeshift: true,
45+
}
46+
)
47+
})
48+
49+
test('test-project App.tsx', async () => {
50+
const rootFwPath = path.dirname(findUp('lerna.json') || '')
51+
const testProjectAppTsx = fs.readFileSync(
52+
path.join(
53+
rootFwPath,
54+
'__fixtures__',
55+
'test-project',
56+
'web',
57+
'src',
58+
'App.tsx'
59+
),
60+
'utf-8'
61+
)
62+
await matchInlineTransformSnapshot(
63+
'appGqlConfigTransform',
64+
testProjectAppTsx,
65+
`import { FatalErrorBoundary, RedwoodProvider } from \"@redwoodjs/web\";
66+
import { RedwoodApolloProvider } from \"@redwoodjs/web/apollo\";
67+
68+
import FatalErrorPage from \"src/pages/FatalErrorPage\";
69+
import Routes from \"src/Routes\";
70+
71+
import { AuthProvider, useAuth } from \"./auth\";
72+
73+
import \"./scaffold.css\";
74+
import \"./index.css\";
75+
76+
const graphQLClientConfig = {
77+
cacheConfig: {
78+
possibleTypes: possibleTypes.possibleTypes,
79+
},
80+
};
81+
82+
const App = () => (
83+
<FatalErrorBoundary page={FatalErrorPage}>
84+
<RedwoodProvider titleTemplate=\"%PageTitle | %AppTitle\">
85+
<AuthProvider>
86+
<RedwoodApolloProvider
87+
useAuth={useAuth}
88+
graphQLClientConfig={graphQLClientConfig}
89+
>
90+
<Routes />
91+
</RedwoodApolloProvider>
92+
</AuthProvider>
93+
</RedwoodProvider>
94+
</FatalErrorBoundary>
95+
);
96+
97+
export default App;
98+
`
99+
)
100+
})
101+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
describe('fragments possibleTypes import', () => {
2+
test('Default App.tsx', async () => {
3+
await matchFolderTransform('appImportTransform', 'import-simple', {
4+
useJsCodeshift: true,
5+
})
6+
})
7+
8+
test('App.tsx with existing import', async () => {
9+
await matchFolderTransform('appImportTransform', 'existingImport', {
10+
useJsCodeshift: true,
11+
})
12+
})
13+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { FatalErrorBoundary, RedwoodProvider } from '@redwoodjs/web'
2+
import { RedwoodApolloProvider } from '@redwoodjs/web/apollo'
3+
4+
import possibleTypes from 'src/graphql/possibleTypes'
5+
6+
import FatalErrorPage from 'src/pages/FatalErrorPage'
7+
import Routes from 'src/Routes'
8+
9+
import './scaffold.css'
10+
import './index.css'
11+
12+
const App = () => (
13+
<FatalErrorBoundary page={FatalErrorPage}>
14+
<RedwoodProvider titleTemplate="%PageTitle | %AppTitle">
15+
<RedwoodApolloProvider>
16+
<Routes />
17+
</RedwoodApolloProvider>
18+
</RedwoodProvider>
19+
</FatalErrorBoundary>
20+
)
21+
22+
export default App

0 commit comments

Comments
 (0)