Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions framework-boilerplates/redwoodjs/.env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ DATABASE_URL=file:./dev.db

# disables Prisma CLI update notifier
PRISMA_HIDE_UPDATE_MESSAGE=true

# Option to override the current environment's default api-side log level
# See: https://redwoodjs.com/docs/logger for level options, defaults to "trace" otherwise.
# Most applications want "debug" or "info" during dev, "trace" when you have issues and "warn" in production.
# Ordered by how verbose they are: trace | debug | info | warn | error | silent
# LOG_LEVEL=debug
4 changes: 4 additions & 0 deletions framework-boilerplates/redwoodjs/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# DATABASE_URL=file:./dev.db
# TEST_DATABASE_URL=file:./.redwood/test.db
# PRISMA_HIDE_UPDATE_MESSAGE=true
# LOG_LEVEL=trace
22 changes: 17 additions & 5 deletions framework-boilerplates/redwoodjs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
.idea
.DS_Store
.env
.env*
!.env.example
!.env.defaults
.netlify
.redwood
dev.db
.redwood/*
!.redwood/README.md
dev.db*
dist
dist-babel
node_modules
yarn-error.log
web/public/mockServiceWorker.js

.vercel
web/types/graphql.d.ts
api/types/graphql.d.ts
api/src/lib/generateGraphiQLHeader.*
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.vercel
15 changes: 15 additions & 0 deletions framework-boilerplates/redwoodjs/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Yarn's manifest file. You can configure yarn here.
# See https://yarnpkg.com/configuration/yarnrc.

# For `node_modules` (see `nodeLinker` below), this is almost always the preferred option.
compressionLevel: 0

enableGlobalCache: true

# Lets yarn use hardlinks inside `node_modules` to dedupe packages.
# For a more pnpm-like experience, consider `hardlinks-global` where hardlinks point to a global store.
nmMode: hardlinks-local

# How to install Node packages.
# Heads up: right now, Redwood expects this to be `node-modules`.
nodeLinker: node-modules
2 changes: 2 additions & 0 deletions framework-boilerplates/redwoodjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ To get started with RedwoodJS on Vercel, you can [use Yarn to initialize](https:
```shell
$ yarn create redwood-app ./my-redwood-app
```

This repository enables the [Corepack](https://vercel.com/docs/builds/configure-a-build#corepack) using the [build.env](https://vercel.com/docs/project-configuration#build.env) property in the `vercel.json` file. However, we recommend adding `ENABLE_EXPERIMENTAL_COREPACK=1` as an Environment Variable in your project settings instead.
1 change: 0 additions & 1 deletion framework-boilerplates/redwoodjs/api/.babelrc.js

This file was deleted.

8 changes: 7 additions & 1 deletion framework-boilerplates/redwoodjs/api/db/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
datasource DS {
// Don't forget to tell Prisma about your edits to this file using
// `yarn rw prisma migrate dev` or `yarn rw prisma db push`.
// `migrate` is like committing while `push` is for prototyping.
// Read more about both here:
// https://www.prisma.io/docs/orm/prisma-migrate

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
Expand Down
28 changes: 0 additions & 28 deletions framework-boilerplates/redwoodjs/api/db/seed.js

This file was deleted.

8 changes: 5 additions & 3 deletions framework-boilerplates/redwoodjs/api/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { getConfig } = require('@redwoodjs/core')
// More info at https://redwoodjs.com/docs/project-configuration-dev-test-build

const config = getConfig({ type: 'jest', target: 'node' })
config.displayName.name = 'api'
const config = {
rootDir: '../',
preset: '@redwoodjs/testing/config/jest/api',
}

module.exports = config
40 changes: 36 additions & 4 deletions framework-boilerplates/redwoodjs/api/jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
{
"compilerOptions": {
"baseUrl": ".",
"noEmit": true,
"esModuleInterop": true,
"target": "ES2023",
"module": "Node16",
"moduleResolution": "Node16",
"skipLibCheck": false,
"rootDirs": [
"./src",
"../.redwood/types/mirror/api/src"
],
"paths": {
"src/*": ["./src/*"]
}
"src/*": [
"./src/*",
"../.redwood/types/mirror/api/src/*"
],
"types/*": [
"./types/*",
"../types/*"
],
"@redwoodjs/testing": [
"../node_modules/@redwoodjs/testing/api"
]
},
"typeRoots": [
"../node_modules/@types",
"./node_modules/@types"
],
"types": [
"jest"
],
"jsx": "react-jsx"
},
"include": ["src/**/*", "../.redwood/index.d.ts"]
"include": [
"src",
"../.redwood/types/includes/all-*",
"../.redwood/types/includes/api-*",
"../types"
]
}
3 changes: 2 additions & 1 deletion framework-boilerplates/redwoodjs/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"@redwoodjs/api": "^0.25.0"
"@redwoodjs/api": "8.8.1",
"@redwoodjs/graphql-server": "8.8.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import gql from 'graphql-tag'

import { createValidatorDirective } from '@redwoodjs/graphql-server'

import { requireAuth as applicationRequireAuth } from 'src/lib/auth'

export const schema = gql`
"""
Use to check whether or not a user is authenticated and is associated
with an optional set of roles.
"""
directive @requireAuth(roles: [String]) on FIELD_DEFINITION
`

const validate = ({ directiveArgs }) => {
const { roles } = directiveArgs
applicationRequireAuth({ roles })
}

const requireAuth = createValidatorDirective(schema, validate)

export default requireAuth
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { mockRedwoodDirective, getDirectiveName } from '@redwoodjs/testing/api'

import requireAuth from './requireAuth'

describe('requireAuth directive', () => {
it('declares the directive sdl as schema, with the correct name', () => {
expect(requireAuth.schema).toBeTruthy()
expect(getDirectiveName(requireAuth.schema)).toBe('requireAuth')
})

it('requireAuth has stub implementation. Should not throw when current user', () => {
// If you want to set values in context, pass it through e.g.
// mockRedwoodDirective(requireAuth, { context: { currentUser: { id: 1, name: 'Lebron McGretzky' } }})
const mockExecution = mockRedwoodDirective(requireAuth, { context: {} })

expect(mockExecution).not.toThrowError()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import gql from 'graphql-tag'

import { createValidatorDirective } from '@redwoodjs/graphql-server'

export const schema = gql`
"""
Use to skip authentication checks and allow public access.
"""
directive @skipAuth on FIELD_DEFINITION
`

const skipAuth = createValidatorDirective(schema, () => {
return
})

export default skipAuth
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getDirectiveName } from '@redwoodjs/testing/api'

import skipAuth from './skipAuth'

describe('skipAuth directive', () => {
it('declares the directive sdl as schema, with the correct name', () => {
expect(skipAuth.schema).toBeTruthy()
expect(getDirectiveName(skipAuth.schema)).toBe('skipAuth')
})
})
21 changes: 10 additions & 11 deletions framework-boilerplates/redwoodjs/api/src/functions/graphql.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import {
createGraphQLHandler,
makeMergedSchema,
makeServices,
} from '@redwoodjs/api'
import { createGraphQLHandler } from '@redwoodjs/graphql-server'

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

import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'

export const handler = createGraphQLHandler({
schema: makeMergedSchema({
schemas,
services: makeServices({ services }),
}),
loggerConfig: { logger, options: {} },
directives,
sdls,
services,
onException: () => {
// Disconnect from your database with an unhandled exception.
db.$disconnect()
Expand Down
32 changes: 32 additions & 0 deletions framework-boilerplates/redwoodjs/api/src/lib/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Once you are ready to add authentication to your application
* you'll build out requireAuth() with real functionality. For
* now we just return `true` so that the calls in services
* have something to check against, simulating a logged
* in user that is allowed to access that service.
*
* See https://redwoodjs.com/docs/authentication for more info.
*/
export const isAuthenticated = () => {
return true
}

export const hasRole = ({ roles }) => {
return roles !== undefined
}

// This is used by the redwood directive
// in ./api/src/directives/requireAuth

// Roles are passed in by the requireAuth directive if you have auth setup
// eslint-disable-next-line no-unused-vars
export const requireAuth = ({ roles }) => {
return isAuthenticated()
}

export const getCurrentUser = async () => {
throw new Error(
'Auth is not set up yet. See https://redwoodjs.com/docs/authentication ' +
'to get started'
)
}
22 changes: 21 additions & 1 deletion framework-boilerplates/redwoodjs/api/src/lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,24 @@

import { PrismaClient } from '@prisma/client'

export const db = new PrismaClient()
import { emitLogLevels, handlePrismaLogging } from '@redwoodjs/api/logger'

import { logger } from './logger'

const prismaClient = new PrismaClient({
log: emitLogLevels(['info', 'warn', 'error']),
})

handlePrismaLogging({
db: prismaClient,
logger,
logLevels: ['info', 'warn', 'error'],
})

/**
* Global Prisma client extensions should be added here, as $extend
* returns a new instance.
* export const db = prismaClient.$extend(...)
* Add any .$on hooks before using $extend
*/
export const db = prismaClient
17 changes: 17 additions & 0 deletions framework-boilerplates/redwoodjs/api/src/lib/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createLogger } from '@redwoodjs/api/logger'

/**
* Creates a logger with RedwoodLoggerOptions
*
* These extend and override default LoggerOptions,
* can define a destination like a file or other supported pino log transport stream,
* and sets whether or not to show the logger configuration settings (defaults to false)
*
* @param RedwoodLoggerOptions
*
* RedwoodLoggerOptions have
* @param {options} LoggerOptions - defines how to log, such as redaction and format
* @param {string | DestinationStream} destination - defines where to log, such as a transport stream or file
* @param {boolean} showConfig - whether to display logger configuration on initialization
*/
export const logger = createLogger({})
3 changes: 0 additions & 3 deletions framework-boilerplates/redwoodjs/babel.config.js

This file was deleted.

12 changes: 8 additions & 4 deletions framework-boilerplates/redwoodjs/graphql.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const { getConfig } = require('@redwoodjs/internal')
// This file is used by the VSCode GraphQL extension

const config = getConfig()
const { getPaths } = require('@redwoodjs/project-config')

module.exports = {
schema: `http://${config.api.host}:${config.api.port}/graphql`,
/** @type {import('graphql-config').IGraphQLConfig} */
const config = {
schema: getPaths().generated.schema,
documents: './web/src/**/!(*.d).{ts,tsx,js,jsx}',
}

module.exports = config
8 changes: 8 additions & 0 deletions framework-boilerplates/redwoodjs/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This the Redwood root jest config
// Each side, e.g. ./web/ and ./api/ has specific config that references this root
// More info at https://redwoodjs.com/docs/project-configuration-dev-test-build

module.exports = {
rootDir: '.',
projects: ['<rootDir>/{*,!(node_modules)/**/}/jest.config.js'],
}
Loading