Skip to content

Commit

Permalink
Merge branch 'main' of github.com:redwoodjs/redwood into feat/make-vi…
Browse files Browse the repository at this point in the history
…te-default

* 'main' of github.com:redwoodjs/redwood: (23 commits)
  chore(deps): update dependency @clerk/clerk-react to v4.16.2 (redwoodjs#8362)
  chore(package size): implement `findup-sync` in `@redwoodjs/project-config` (redwoodjs#8315)
  Refactor GraphQL Server and CreateYoga to Support "api serve" with Fastify Server (redwoodjs#8339)
  chore(deps): update dependency octokit to v2.0.15 (redwoodjs#8360)
  fix(coherence): correct doc links, add commas to template (redwoodjs#8351)
  Parse as int, fix jsdoc (redwoodjs#8357)
  Update forms.md (redwoodjs#8352)
  chore: update yarn.lock
  chore(release): update release command for minors
  chore(deps): update dependency rimraf to v5.0.1 (redwoodjs#8350)
  chore(deps): update dependency glob to v10.2.5 (redwoodjs#8349)
  feat(coherence deploy): add setup deploy coherence (redwoodjs#8234)
  fix(deps): update dependency listr2 to v6.6.0 (redwoodjs#8347)
  fix(deps): update dependency react-router-dom to v6.11.2 (redwoodjs#8345)
  fix(deps): update prisma monorepo to v4.14.1 (redwoodjs#8346)
  fix(deps): update dependency webpack to v5.83.1 (redwoodjs#8348)
  chore(deps): update dependency dependency-cruiser to v13 (redwoodjs#8322)
  chore(deps): update dependency @clerk/clerk-react to v4.16.1 (redwoodjs#8324)
  chore(deps): update dependency @clerk/types to v3.38.0 (redwoodjs#8325)
  chore(deps): update dependency nx to v16.2.1 (redwoodjs#8343)
  ...
  • Loading branch information
dac09 committed May 19, 2023
2 parents 2038b78 + ad4bf6d commit 2d2a193
Show file tree
Hide file tree
Showing 100 changed files with 1,825 additions and 1,516 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const path = require('path')

const findUp = require('findup-sync')
const { findUp } = require('@redwoodjs/project-config')

// Framework Babel config is monorepo root ./babel.config.js
// `yarn lint` runs for each workspace, which needs findup for path to root
// `yarn lint` runs for each workspace, which needs findUp for path to root
const findBabelConfig = (cwd = process.cwd()) => {
const configPath = findUp('babel.config.js', { cwd })
const configPath = findUp('babel.config.js', cwd)
if (!configPath) {
throw new Error(`Eslint-parser could not find a "babel.config.js" file`)
}
Expand Down
40 changes: 40 additions & 0 deletions docs/docs/deploy/coherence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
description: Serverful deploys on GCP or AWS via Coherence's full-lifecycle environment automation
---

# Deploy to Coherence

[Coherence](https://www.withcoherence.com/) delivers automated environments across the full software development lifecycle, without requiring you to glue together your own mess of open source tools to get a world-class develper experience for your team. Coherence is focused on serving startups, who are doing mission-critical work. With one simple configuration, Coherence offers:

- Cloud-hosted development environments, based on VSCode. Similar to Gitpod or GitHub CodeSpaces
- Production-ready CI/CD running in your own GCP/AWS account, including: database migration/seeding/snapshot loading, parallelized tests, container building and docker registry management
- Full-stack branch previews. Vercel/Netlify-like developer experience for arbitrary container apps, including dependencies such as CDN, redis, and database resources
- Staging and production environment management in your AWS/GCP accounts. Production runs in its own cloud account (AWS) or project (GCP). Integrated secrets management across all environment types with a developer-friendly UI

## Coherence Prerequisites

To deploy to Coherence, your Redwood project needs to be hosted on GitHub and you must have an [AWS](https://docs.withcoherence.com/docs/overview/aws-deep-dive) or [GCP](https://docs.withcoherence.com/docs/overview/gcp-deep-dive) account.

## Coherence Deploy

:::caution Prerender doesn't work with Coherence yet

You can see its current status and follow updates here on GitHub: https://github.com/redwoodjs/redwood/issues/8333.

But if you don't use prerender, carry on!

:::

If you want to deploy your Redwood project on Coherence, run the setup command:

```
yarn rw setup deploy coherence
```

The command will inspect your Prisma config to determine if you're using a supported database (at the moment, only `postgres` or `mysql` are supported on Coherence).

Then follow the [Coherence Redwood deploy docs](https://docs.withcoherence.com/docs/configuration/frameworks#redwood-js) for more information, including if you want to set up:
- a redis server
- database migration/seeding/snapshot loading
- cron jobs or async workers
- object storage using Google Cloud Storage or AWS's S3
1 change: 1 addition & 0 deletions docs/docs/deploy/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Redwood is designed for both serverless and traditional infrastructure deploymen

Currently, these are the officially supported deploy targets:
- Baremetal (physical server that you have SSH access to)
- [Coherence](https://www.withcoherence.com/)
- [Flightcontrol.dev](https://www.flightcontrol.dev?ref=redwood)
- [Edg.io](https://edg.io)
- [Netlify.com](https://www.netlify.com/)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ All of Redwood's form helpers need the `register` function to do what they do. B

### Using `formMethods`

There's some functions that `useForm` returns that it'd be nice to have access to.
There are some functions that `useForm` returns that it'd be nice to have access to.
For example, `useForm` returns a function `reset`, which resets the form's fields.
To access it, you have to call `useForm` yourself.
But you still need to pass `useForm`'s return to the `<FormProvider>` so that Redwood's helpers can register themselves:
Expand Down
10 changes: 8 additions & 2 deletions docs/docs/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -1452,9 +1452,9 @@ The [GraphQL Playground](https://www.graphql-yoga.com/docs/features/graphiql) is
> Because both introspection and the playground share possibly sensitive information about your data model, your data, your queries and mutations, best practices for deploying a GraphQL Server call to disable these in production, RedwoodJS **, by default, only enables introspection and the playground when running in development**. That is when `process.env.NODE_ENV === 'development'`.
However, there may be cases where you want to enable introspection. You can enable introspection by setting the `allowIntrospection` option to `true`.
However, there may be cases where you want to enable introspection as well as the GraphQL PLaygrouns. You can enable introspection by setting the `allowIntrospection` option to `true` and enable GraphiQL by setting `allowGraphiQL` to `true`.
Here is an example of `createGraphQLHandler` function with the `allowIntrospection` option set to `true`:
Here is an example of `createGraphQLHandler` function with the `allowIntrospection` and `allowGraphiQL` options set to `true`:
```ts {8}
export const handler = createGraphQLHandler({
authDecoder,
Expand All @@ -1464,6 +1464,7 @@ export const handler = createGraphQLHandler({
sdls,
services,
allowIntrospection: true, // 👈 enable introspection in all environments
allowGraphiQL: true, // 👈 enable GraphiQL Playground in all environments
onException: () => {
// Disconnect from your database with an unhandled exception.
db.$disconnect()
Expand All @@ -1475,8 +1476,13 @@ export const handler = createGraphQLHandler({
Enabling introspection in production may pose a security risk, as it allows users to access information about your schema, queries, and mutations. Use this option with caution and make sure to secure your GraphQL API properly.
The may be cases where one wants to allow introspection, but not GraphiQL.
Or, you may want to enable GraphiQL, but not allow introspection; for example, to try out known queries, but not to share the entire set of possible operations and types.
:::
### GraphQL Armor Configuration
[GraphQL Armor](https://escape.tech/graphql-armor/) is a middleware that adds a security layer the RedwoodJS GraphQL endpoint configured with sensible defaults.
Expand Down
5 changes: 5 additions & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ module.exports = {
items: [
{ type: 'doc', label: 'Introduction', id: 'deploy/introduction' },
{ type: 'doc', label: 'Baremetal', id: 'deploy/baremetal' },
{
type: 'doc',
label: 'GCP or AWS via Coherence',
id: 'deploy/coherence',
},
{
type: 'doc',
label: 'AWS via Flightcontrol',
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@
"jest-runner-tsd": "5.0.0",
"jscodeshift": "0.15.0",
"lerna": "6.6.2",
"listr2": "6.5.0",
"listr2": "6.6.0",
"lodash.template": "4.5.0",
"make-dir-cli": "3.0.0",
"msw": "1.2.1",
"ncp": "2.0.0",
"nodemon": "2.0.22",
"npm-packlist": "7.0.4",
"nx": "16.1.4",
"nx": "16.2.1",
"nx-cloud": "16.0.5",
"octokit": "2.0.14",
"octokit": "2.0.15",
"ora": "5.4.1",
"prompts": "2.4.2",
"rimraf": "5.0.0",
"rimraf": "5.0.1",
"typescript": "5.0.4",
"yargs": "17.7.2",
"zx": "7.2.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
},
"dependencies": {
"@babel/runtime-corejs3": "7.21.5",
"@prisma/client": "4.14.0",
"@whatwg-node/fetch": "0.8.8",
"@prisma/client": "4.14.1",
"@whatwg-node/fetch": "0.9.0",
"core-js": "3.30.2",
"humanize-string": "2.1.0",
"jsonwebtoken": "9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-providers/clerk/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@babel/runtime-corejs3": "7.21.5",
"@clerk/clerk-sdk-node": "4.8.7",
"@clerk/clerk-sdk-node": "4.9.1",
"core-js": "3.30.2"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/auth-providers/clerk/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
"devDependencies": {
"@babel/cli": "7.21.5",
"@babel/core": "7.21.8",
"@clerk/clerk-react": "4.15.4",
"@clerk/types": "3.36.0",
"@clerk/clerk-react": "4.16.2",
"@clerk/types": "3.38.0",
"@types/react": "18.2.6",
"jest": "29.5.0",
"react": "18.2.0",
"typescript": "5.0.4"
},
"peerDependencies": {
"@clerk/clerk-react": "4.15.4"
"@clerk/clerk-react": "4.16.2"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
2 changes: 1 addition & 1 deletion packages/cli-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"chalk": "4.1.2",
"core-js": "3.30.2",
"execa": "5.1.1",
"listr2": "6.5.0",
"listr2": "6.6.0",
"lodash.memoize": "4.1.2",
"pascalcase": "1.0.0",
"prettier": "2.8.8",
Expand Down
9 changes: 4 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@babel/runtime-corejs3": "7.21.5",
"@iarna/toml": "2.2.5",
"@prisma/internals": "4.14.0",
"@prisma/internals": "4.14.1",
"@redwoodjs/api-server": "5.0.0",
"@redwoodjs/cli-helpers": "5.0.0",
"@redwoodjs/fastify": "5.0.0",
Expand All @@ -54,20 +54,19 @@
"envinfo": "7.8.1",
"execa": "5.1.1",
"fast-glob": "3.2.12",
"findup-sync": "5.0.0",
"fs-extra": "11.1.1",
"humanize-string": "2.1.0",
"latest-version": "5.1.0",
"listr2": "6.5.0",
"listr2": "6.6.0",
"lodash": "4.17.21",
"param-case": "3.0.4",
"pascalcase": "1.0.0",
"pluralize": "8.0.0",
"portfinder": "1.0.32",
"prettier": "2.8.8",
"prisma": "4.14.0",
"prisma": "4.14.1",
"prompts": "2.4.2",
"rimraf": "5.0.0",
"rimraf": "5.0.1",
"secure-random-password": "0.2.3",
"semver": "7.5.1",
"string-env-interpolation": "1.0.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/devHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ export const handler = async ({
...forward.matchAll(/\-\-port(\=|\s)(?<port>[^\s]*)/g),
]
if (forwardedPortMatches.length) {
webPreferredPort = forwardedPortMatches.pop().groups.port
webPreferredPort = parseInt(forwardedPortMatches.pop().groups.port)
}

webAvailablePort = await getFreePort(webPreferredPort, [
apiPreferredPort,
apiAvailablePort,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
import path from 'path'

// import { useLiveQuery } from '@envelop/live-query'
import chalk from 'chalk'
import { config } from 'dotenv-defaults'
import Fastify from 'fastify'
import { OperationTypeNode } from 'graphql'

import {
coerceRootPath,
redwoodFastifyWeb,
redwoodFastifyAPI,
redwoodFastifyGraphQLServer,
DEFAULT_REDWOOD_FASTIFY_CONFIG,
} from '@redwoodjs/fastify'
import { getPaths, getConfig } from '@redwoodjs/project-config'

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

import { logger } from './lib/logger'

async function serve() {
// Load .env files
const redwoodProjectPaths = getPaths()
const redwoodConfig = getConfig()

const apiRootPath = coerceRootPath(redwoodConfig.web.apiUrl)
const port = redwoodConfig.web.port

const tsServer = Date.now()

config({
path: path.join(redwoodProjectPaths.base, '.env'),
defaults: path.join(redwoodProjectPaths.base, '.env.defaults'),
multiline: true,
})

const tsServer = Date.now()
console.log(chalk.italic.dim('Starting API and Web Servers...'))

// Configure Fastify
const fastify = Fastify({
...DEFAULT_REDWOOD_FASTIFY_CONFIG,
})

const redwoodConfig = getConfig()

const apiRootPath = coerceRootPath(redwoodConfig.web.apiUrl)
const port = redwoodConfig.web.port

await fastify.register(redwoodFastifyWeb)

await fastify.register(redwoodFastifyAPI, {
Expand All @@ -43,6 +52,24 @@ async function serve() {
},
})

await fastify.register(redwoodFastifyGraphQLServer, {
loggerConfig: {
logger: logger,
options: { query: true, data: true, level: 'trace' },
},
graphiQLEndpoint: '/yoga',
sdls,
services,
directives,
allowIntrospection: true,
allowGraphiQL: true,
allowedOperations: [
OperationTypeNode.SUBSCRIPTION,
OperationTypeNode.QUERY,
OperationTypeNode.MUTATION,
],
})

// Start
fastify.listen({ port })

Expand All @@ -55,7 +82,7 @@ async function serve() {
console.log(`API serving from ${apiServer}`)
console.log(`API listening on ${on}`)
const graphqlEnd = chalk.magenta(`${apiRootPath}graphql`)
console.log(`GraphQL endpoint at ${graphqlEnd}`)
console.log(`GraphQL function endpoint at ${graphqlEnd}`)
})

process.on('exit', () => {
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/src/commands/setup/deploy/providers/coherence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const command = 'coherence'

export const description = 'Setup Coherence deploy'

export function builder(yargs) {
yargs.option('force', {
description: 'Overwrite existing configuration',
type: 'boolean',
default: false,
})
}

export async function handler(options) {
const { handler } = await import('./coherenceHandler')
return handler(options)
}
Loading

0 comments on commit 2d2a193

Please sign in to comment.