Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds Setup CLI Command to Configure GraphQL Trusted Documents #9800

Merged
merged 27 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
446ae64
WIP to have graphql setup of trusted docs
dthyresson Jan 4, 2024
cc647b3
cleanup command and add docs
dthyresson Jan 4, 2024
608b5d4
Update docs/docs/cli-commands.md
dthyresson Jan 8, 2024
9cd43eb
Update docs/docs/cli-commands.md
dthyresson Jan 8, 2024
bc27569
Update docs/docs/cli-commands.md
dthyresson Jan 8, 2024
a68de95
Update docs/docs/graphql/trusted-documents.md
dthyresson Jan 8, 2024
75773d6
Refactor to improve toml setup
dthyresson Jan 8, 2024
8f15513
removed commandDir
dthyresson Jan 8, 2024
717be40
removed force option
dthyresson Jan 8, 2024
27d6cdc
Merge branch 'main' into dt-setup-gql-trusted-docs
dthyresson Jan 8, 2024
d9eeed3
Adds tests for trusted document toml updates
dthyresson Jan 9, 2024
1677049
Tests for graphql handler store updates
dthyresson Jan 9, 2024
d865c58
Merge branch 'main' into dt-setup-gql-trusted-docs
Tobbe Jan 11, 2024
89a06df
async handler and TS fixes
Tobbe Jan 11, 2024
d69acf3
Fix import and TS issue in test
Tobbe Jan 11, 2024
2cb9ad3
Update test snapshot
Tobbe Jan 11, 2024
2b551f2
More robust redwood.toml handling
Tobbe Jan 11, 2024
e01e962
Fix tsconfig
Tobbe Jan 11, 2024
063a67f
Move all tasks to array, and silence logs in test
Tobbe Jan 11, 2024
7ad7da2
Move __fixtures__
Tobbe Jan 11, 2024
23f281c
Fix whiteline in test
Tobbe Jan 11, 2024
bd476be
fragments: refactor->rename
Tobbe Jan 12, 2024
6b144bb
Move to jscodeshift
Tobbe Jan 12, 2024
911f3fe
Merge branch 'main' into dt-setup-gql-trusted-docs
Tobbe Jan 12, 2024
c8f0bbb
Fix paths
Tobbe Jan 12, 2024
f5af938
Update filepath in test
Tobbe Jan 12, 2024
d4615ac
Merge branch 'main' into dt-setup-gql-trusted-docs
Tobbe Jan 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion docs/docs/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,7 @@ It's the author of the npm package's responsibility to specify the correct compa

### setup graphql

This command creates the necessary files to support GraphQL features like fragments.
This command creates the necessary files to support GraphQL features like fragments and trusted documents.

#### Usage

Expand Down Expand Up @@ -2033,6 +2033,38 @@ Run `yarn rw setup graphql fragments`
✔ 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.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe('trusted-documents graphql handler transform', () => {
test('Default handler', async () => {
await matchFolderTransform('graphqlTransform', 'graphql', {
useJsCodeshift: true,
})
})

test('Handler with the store already set up', async () => {
await matchFolderTransform('graphqlTransform', 'alreadySetUp', {
useJsCodeshift: true,
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createAuthDecoder } from '@redwoodjs/auth-dbauth-api'
import { createGraphQLHandler } from '@redwoodjs/graphql-server'

import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
import services from 'src/services/**/*.{js,ts}'

import { cookieName, getCurrentUser } from 'src/lib/auth'
import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'

import { store } from 'src/lib/trustedDocumentsStore'

const authDecoder = createAuthDecoder(cookieName)

export const handler = createGraphQLHandler({
authDecoder,
getCurrentUser,
loggerConfig: { logger, options: {} },
directives,
sdls,
services,

onException: () => {
// Disconnect from your database with an unhandled exception.
db.$disconnect()
},

trustedDocuments: {
store
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createAuthDecoder } from '@redwoodjs/auth-dbauth-api'
import { createGraphQLHandler } from '@redwoodjs/graphql-server'

import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
import services from 'src/services/**/*.{js,ts}'

import { cookieName, getCurrentUser } from 'src/lib/auth'
import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'

import { store } from 'src/lib/trustedDocumentsStore'

const authDecoder = createAuthDecoder(cookieName)

export const handler = createGraphQLHandler({
authDecoder,
getCurrentUser,
loggerConfig: { logger, options: {} },
directives,
sdls,
services,

onException: () => {
// Disconnect from your database with an unhandled exception.
db.$disconnect()
},

trustedDocuments: {
store
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createAuthDecoder } from '@redwoodjs/auth-dbauth-api'
import { createGraphQLHandler } from '@redwoodjs/graphql-server'

import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
import services from 'src/services/**/*.{js,ts}'

import { cookieName, getCurrentUser } from 'src/lib/auth'
import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'

const authDecoder = createAuthDecoder(cookieName)

export const handler = createGraphQLHandler({
authDecoder,
getCurrentUser,
loggerConfig: { logger, options: {} },
directives,
sdls,
services,
onException: () => {
// Disconnect from your database with an unhandled exception.
db.$disconnect()
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createAuthDecoder } from '@redwoodjs/auth-dbauth-api'
import { createGraphQLHandler } from '@redwoodjs/graphql-server'

import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
import services from 'src/services/**/*.{js,ts}'

import { cookieName, getCurrentUser } from 'src/lib/auth'
import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'

import { store } from 'src/lib/trustedDocumentsStore'

const authDecoder = createAuthDecoder(cookieName)

export const handler = createGraphQLHandler({
authDecoder,
getCurrentUser,
loggerConfig: { logger, options: {} },
directives,
sdls,
services,

onException: () => {
// Disconnect from your database with an unhandled exception.
db.$disconnect()
},

trustedDocuments: {
store
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file contains the configuration settings for your Redwood app.
# This file is also what makes your Redwood app a Redwood app.
# If you remove it and try to run `yarn rw dev`, you'll get an error.
#
# For the full list of options, see the "App Configuration: redwood.toml" doc:
# https://redwoodjs.com/docs/app-configuration-redwood-toml

[web]
title = "Redwood App"
port = "${WEB_DEV_PORT:8910}"
apiUrl = "/.redwood/functions" # You can customize graphql and dbauth urls individually too: see https://redwoodjs.com/docs/app-configuration-redwood-toml#api-paths
includeEnvironmentVariables = [
# Add any ENV vars that should be available to the web side to this array
# See https://redwoodjs.com/docs/environment-variables#web
]
[api]
port = "${API_DEV_PORT:8911}"
[browser]
open = true
[notifications]
versionUpdates = ["latest"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file contains the configuration settings for your Redwood app.
# This file is also what makes your Redwood app a Redwood app.
# If you remove it and try to run `yarn rw dev`, you'll get an error.
#
# For the full list of options, see the "App Configuration: redwood.toml" doc:
# https://redwoodjs.com/docs/app-configuration-redwood-toml

[web]
title = "Redwood App"
port = "${WEB_DEV_PORT:8910}"
apiUrl = "/.redwood/functions" # You can customize graphql and dbauth urls individually too: see https://redwoodjs.com/docs/app-configuration-redwood-toml#api-paths
includeEnvironmentVariables = [
# Add any ENV vars that should be available to the web side to this array
# See https://redwoodjs.com/docs/environment-variables#web
]
[api]
port = "${API_DEV_PORT:8911}"
[graphql]
fragments = true
[browser]
open = true
[notifications]
versionUpdates = ["latest"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file contains the configuration settings for your Redwood app.
# This file is also what makes your Redwood app a Redwood app.
# If you remove it and try to run `yarn rw dev`, you'll get an error.
#
# For the full list of options, see the "App Configuration: redwood.toml" doc:
# https://redwoodjs.com/docs/app-configuration-redwood-toml

[web]
title = "Redwood App"
port = "${WEB_DEV_PORT:8910}"
apiUrl = "/.redwood/functions" # You can customize graphql and dbauth urls individually too: see https://redwoodjs.com/docs/app-configuration-redwood-toml#api-paths
includeEnvironmentVariables = [
# Add any ENV vars that should be available to the web side to this array
# See https://redwoodjs.com/docs/environment-variables#web
]
[api]
port = "${API_DEV_PORT:8911}"
[graphql]
fragments=true
[browser]
open = true
[notifications]
versionUpdates = ["latest"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file contains the configuration settings for your Redwood app.
# This file is also what makes your Redwood app a Redwood app.
# If you remove it and try to run `yarn rw dev`, you'll get an error.
#
# For the full list of options, see the "App Configuration: redwood.toml" doc:
# https://redwoodjs.com/docs/app-configuration-redwood-toml

[web]
title = "Redwood App"
port = "${WEB_DEV_PORT:8910}"
apiUrl = "/.redwood/functions" # You can customize graphql and dbauth urls individually too: see https://redwoodjs.com/docs/app-configuration-redwood-toml#api-paths
includeEnvironmentVariables = [
# Add any ENV vars that should be available to the web side to this array
# See https://redwoodjs.com/docs/environment-variables#web
]
[api]
port = "${API_DEV_PORT:8911}"
[graphql]
trustedDocuments = true
fragments = true
[browser]
open = true
[notifications]
versionUpdates = ["latest"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file contains the configuration settings for your Redwood app.
# This file is also what makes your Redwood app a Redwood app.
# If you remove it and try to run `yarn rw dev`, you'll get an error.
#
# For the full list of options, see the "App Configuration: redwood.toml" doc:
# https://redwoodjs.com/docs/app-configuration-redwood-toml

[web]
title = "Redwood App"
port = "${WEB_DEV_PORT:8910}"
apiUrl = "/.redwood/functions" # You can customize graphql and dbauth urls individually too: see https://redwoodjs.com/docs/app-configuration-redwood-toml#api-paths
includeEnvironmentVariables = [
# Add any ENV vars that should be available to the web side to this array
# See https://redwoodjs.com/docs/environment-variables#web
]
[api]
port = "${API_DEV_PORT:8911}"
# [graphql]
# trustedDocuments = true
[browser]
open = true
[notifications]
versionUpdates = ["latest"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file contains the configuration settings for your Redwood app.
# This file is also what makes your Redwood app a Redwood app.
# If you remove it and try to run `yarn rw dev`, you'll get an error.
#
# For the full list of options, see the "App Configuration: redwood.toml" doc:
# https://redwoodjs.com/docs/app-configuration-redwood-toml

[web]
title = "Redwood App"
port = "${WEB_DEV_PORT:8910}"
apiUrl = "/.redwood/functions" # You can customize graphql and dbauth urls individually too: see https://redwoodjs.com/docs/app-configuration-redwood-toml#api-paths
includeEnvironmentVariables = [
# Add any ENV vars that should be available to the web side to this array
# See https://redwoodjs.com/docs/environment-variables#web
]
[api]
port = "${API_DEV_PORT:8911}"
[graphql]
trustedDocuments = true
fragments = true
[browser]
open = true
[notifications]
versionUpdates = ["latest"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file contains the configuration settings for your Redwood app.
# This file is also what makes your Redwood app a Redwood app.
# If you remove it and try to run `yarn rw dev`, you'll get an error.
#
# For the full list of options, see the "App Configuration: redwood.toml" doc:
# https://redwoodjs.com/docs/app-configuration-redwood-toml

[web]
title = "Redwood App"
port = "${WEB_DEV_PORT:8910}"
apiUrl = "/.redwood/functions" # You can customize graphql and dbauth urls individually too: see https://redwoodjs.com/docs/app-configuration-redwood-toml#api-paths
includeEnvironmentVariables = [
# Add any ENV vars that should be available to the web side to this array
# See https://redwoodjs.com/docs/environment-variables#web
]
[api]
port = "${API_DEV_PORT:8911}"
[graphql]
trustedDocuments=true
[browser]
open = true
[notifications]
versionUpdates = ["latest"]
Loading