Skip to content

Commit

Permalink
Merge branch 'main' of github.com:redwoodjs/redwood into feat/dbauth-…
Browse files Browse the repository at this point in the history
…fetch-handler

* 'main' of github.com:redwoodjs/redwood:
  Add missing cli-helpers test file (redwoodjs#9833)
  Add cli-helpers util to update redwood.toml (redwoodjs#9832)
  Tweak graphiql setup messages (redwoodjs#9831)
  exp setup sentry: Fix file extension (redwoodjs#9829)
  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)
  • Loading branch information
dac09 committed Jan 16, 2024
2 parents be84ace + d9892f4 commit c3a2ebb
Show file tree
Hide file tree
Showing 78 changed files with 3,994 additions and 70 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
'packages/babel-config/src/__tests__/__fixtures__/**/*',
'packages/core/**/__fixtures__/**/*',
'packages/codemods/**/__testfixtures__/**/*',
'packages/cli/**/__testfixtures__/**/*',
'packages/core/config/storybook/**/*',
'packages/studio/dist-*/**/*',
],
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,18 @@ jobs:
REDWOOD_TEST_PROJECT_PATH: '${{ steps.set-up-test-project.outputs.test-project-path }}'
REDWOOD_DISABLE_TELEMETRY: 1

- name: Enable trusted-documents in Fragments test project
run: npx -y tsx ./tasks/test-project/set-up-trusted-documents ${{ steps.set-up-test-project.outputs.test-project-path }}
env:
REDWOOD_DISABLE_TELEMETRY: 1

- name: 📄 Run prerender smoke tests against Fragments test project (with trusted-documents enabled)
working-directory: tasks/smoke-tests/prerender
run: npx playwright test
env:
REDWOOD_TEST_PROJECT_PATH: ${{ steps.set-up-test-project.outputs.test-project-path }}
REDWOOD_DISABLE_TELEMETRY: 1

fragments-smoke-tests-skip:
needs: detect-changes

Expand Down
67 changes: 66 additions & 1 deletion docs/docs/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1999,11 +1999,76 @@ We perform a simple compatibility check in an attempt to make you aware of poten
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!
### setup graphql
This command creates the necessary files to support GraphQL features like fragments and trusted documents.
#### Usage
Run `yarn rw setup graphql <feature>`
#### setup graphql fragments
This command creates the necessary configuration to start using [GraphQL Fragments](./graphql/fragments.md).
```
yarn redwood setup graphql fragments
```
| Arguments & Options | Description |
| :------------------ | :--------------------------------------- |
| `--force, -f` | Overwrite existing files and skip checks |
#### Usage
Run `yarn rw setup graphql fragments`
#### Example
```bash
~/redwood-app$ yarn rw setup graphql fragments
✔ Update Redwood Project Configuration to enable GraphQL Fragments
✔ Generate possibleTypes.ts
✔ Import possibleTypes in App.tsx
✔ Add possibleTypes to the GraphQL cache config
```
#### setup graphql trusted-documents
This command creates the necessary configuration to start using [GraphQL Trusted Documents](./graphql/trusted-documents.md).
```
yarn redwood setup graphql trusted-documents
```
#### Usage
Run `yarn rw setup graphql trusted-documents`
#### Example
```bash
~/redwood-app$ yarn rw setup graphql trusted-documents
✔ Update Redwood Project Configuration to enable GraphQL Trusted Documents ...
✔ Generating Trusted Documents store ...
✔ Configuring the GraphQL Handler to use a Trusted Documents store ...
```
If you have not setup the RedwoodJS server file, it will be setup:
```bash
✔ Adding the experimental server file...
✔ Adding config to redwood.toml...
✔ Adding required api packages...
```
### setup realtime
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.
```
yarn redwood setup realtime
```
Expand Down
28 changes: 18 additions & 10 deletions docs/docs/graphql/fragments.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ With `registerFragment`, you can register a fragment with the registry and get b

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

### Setup

`yarn rw setup graphql fragments`

See more in [cli commands - setup graphql fragments](../cli-commands.md#setup-graphql-fragments).

### registerFragment

To register a fragment, you can simply register it with `registerFragment`.
Expand Down Expand Up @@ -200,7 +206,7 @@ the `getCacheKey` is a function where `getCacheKey(42)` would return `Book:42`.
import { registerFragment } from '@redwoodjs/web/apollo'

const { useRegisteredFragment } = registerFragment(
...
// ...
)
```

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


```ts
// web/src/App.tsx

import possibleTypes from 'src/graphql/possibleTypes'

...
/// web/src/App.tsx
<RedwoodApolloProvider
graphQLClientConfig={{
cacheConfig: {
...possibleTypes,
},
}}
>
// ...

const graphQLClientConfig = {
cacheConfig: {
...possibleTypes,
},
}

<RedwoodApolloProvider graphQLClientConfig={graphQLClientConfig}>
```

To generate the `src/graphql/possibleTypes` file, enable fragments in `redwood.toml`:
Expand Down
5 changes: 5 additions & 0 deletions docs/docs/graphql/trusted-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ Thus preventing unwanted queries or GraphQl traversal attacks,

## Configure Trusted Documents

Below are instructions to manually configure Trusted Documents in your RedwoodJS project.

Alternatively, you can use the `yarn redwood setup graphql trusted-documents` [CLI setup command](../cli-commands.md#setup-graphql-trusted-docs).


### Configure redwood.toml

Setting `trustedDocuments` to true will
Expand Down
Loading

0 comments on commit c3a2ebb

Please sign in to comment.