Skip to content

Commit

Permalink
Merge branch 'main' of github.com:redwoodjs/redwood into try/tsd-tests
Browse files Browse the repository at this point in the history
* 'main' of github.com:redwoodjs/redwood:
  fix(deps): update dependency @graphql-yoga/common to v2.12.12 (redwoodjs#6349)
  fix(test-project): revert @redwoodjs/core to rc
  Update yarn.lock
  v2.2.4
  bugfix replace slash in tailwind config on windows (redwoodjs#6203)
  bugfix replace slash in tailwind config on windows (redwoodjs#6203)
  chore(deps): update dependency @testing-library/dom to v8.17.1 (redwoodjs#6351)
  Update yarn.lock
  Use try/catch to access unauthenticated (redwoodjs#6358)
  issue#5852 added windows fix for nodeFileTrace (redwoodjs#6325)
  Handle special props `ref` and `key` in path and search params (redwoodjs#5537)
  Use try/catch to access unauthenticated (redwoodjs#6358)
  feat(codemod): Add codemod to make relation resolvers partial (redwoodjs#6342)
  • Loading branch information
dac09 committed Sep 9, 2022
2 parents b98bba6 + c450ecf commit db82751
Show file tree
Hide file tree
Showing 33 changed files with 357 additions and 127 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.2.3",
"version": "2.2.4",
"npmClient": "yarn",
"useWorkspaces": true,
"useNx": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redwoodjs/api-server",
"version": "2.2.3",
"version": "2.2.4",
"description": "Redwood's HTTP server for Serverless Functions",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redwoodjs/api",
"version": "2.2.3",
"version": "2.2.4",
"repository": {
"type": "git",
"url": "https://github.com/redwoodjs/redwood.git",
Expand Down Expand Up @@ -49,7 +49,7 @@
"@babel/cli": "7.18.10",
"@babel/core": "7.18.13",
"@clerk/clerk-sdk-node": "3.9.2",
"@redwoodjs/auth": "2.2.3",
"@redwoodjs/auth": "2.2.4",
"@simplewebauthn/server": "6.2.0",
"@types/aws-lambda": "8.10.101",
"@types/crypto-js": "4.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redwoodjs/auth",
"version": "2.2.3",
"version": "2.2.4",
"repository": {
"type": "git",
"url": "https://github.com/redwoodjs/redwood.git",
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redwoodjs/cli",
"version": "2.2.3",
"version": "2.2.4",
"description": "The Redwood Command Line",
"repository": {
"type": "git",
Expand Down Expand Up @@ -30,11 +30,11 @@
"dependencies": {
"@babel/runtime-corejs3": "7.18.9",
"@prisma/internals": "4.3.1",
"@redwoodjs/api-server": "2.2.3",
"@redwoodjs/internal": "2.2.3",
"@redwoodjs/prerender": "2.2.3",
"@redwoodjs/structure": "2.2.3",
"@redwoodjs/telemetry": "2.2.3",
"@redwoodjs/api-server": "2.2.4",
"@redwoodjs/internal": "2.2.4",
"@redwoodjs/prerender": "2.2.4",
"@redwoodjs/structure": "2.2.4",
"@redwoodjs/telemetry": "2.2.4",
"boxen": "5.1.2",
"camelcase": "6.3.0",
"chalk": "4.1.2",
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/commands/setup/ui/libraries/tailwindcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ export const handler = async ({ force, install }) => {
const prettierConfigPath = path.join(rwPaths.base, 'prettier.config.js')
// Add tailwindcss ordering plugin to prettier
const prettierConfig = fs.readFileSync(prettierConfigPath, 'utf-8')
const tailwindConfigPath = path.relative(
rwPaths.base,
path.join(rwPaths.web.config, 'tailwind.config.js')
)
const tailwindConfigPath = path
.relative(
rwPaths.base,
path.posix.join(rwPaths.web.config, 'tailwind.config.js')
)
.replaceAll('\\', '/')

let newPrettierConfig = prettierConfig
if (newPrettierConfig.includes('tailwindConfig: ')) {
Expand Down
2 changes: 1 addition & 1 deletion packages/codemods/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redwoodjs/codemods",
"version": "2.2.3",
"version": "2.2.4",
"description": "Codemods to ease upgrading a RedwoodJS Project",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Update Resolver Types

- This codemod only affects TS projects.

It will find all service files, and if they have a relation resolver - it will convert the type to a partial.

Taking a specific case, in the test project we have Post.author, which is a relation (author is User on the DB).

```diff
// At the bottom of the file
- export const Post: PostResolvers = {
+ export const Post: Partial<PostResolvers> = {
author: (_obj, gqlArgs) =>
db.post.findUnique({ where: { id: gqlArgs?.root?.id } }).author(),
}
```

This is because of the `avoidOptionals` flag in graphql codegen. Look for this option in `packages/internal/src/generate/graphqlCodeGen.ts`


> Note:
> Very old RW projects don't even have these types in the services. This was introduced in v2.x, when we enabled Prisma model mapping in codegen.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type {
QueryResolvers,
MutationResolvers,
PostResolvers,
} from 'types/graphql'

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

export const posts: QueryResolvers['posts'] = () => {
return db.post.findMany()
}

export const post: QueryResolvers['post'] = ({ id }) => {
return db.post.findUnique({
where: { id },
})
}

export const createPost: MutationResolvers['createPost'] = ({ input }) => {
return db.post.create({
data: input,
})
}

export const updatePost: MutationResolvers['updatePost'] = ({ id, input }) => {
return db.post.update({
data: input,
where: { id },
})
}

export const deletePost: MutationResolvers['deletePost'] = ({ id }) => {
return db.post.delete({
where: { id },
})
}

export const Post: PostResolvers = {
author: (_obj, gqlArgs) =>
db.post.findUnique({ where: { id: gqlArgs?.root?.id } }).author() as Author,
}

// Leave these alone
interface Bazinga {
bazinga: string
}

export const CustomExport: Bazinga = {
bazinga: 'yes'
}

export const CustomExport2: Partial<Bazinga> = {}

const HelloWorld: BazingaResolvers['HelloWorld'] = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type {
QueryResolvers,
MutationResolvers,
PostResolvers,
} from 'types/graphql'

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

export const posts: QueryResolvers['posts'] = () => {
return db.post.findMany()
}

export const post: QueryResolvers['post'] = ({ id }) => {
return db.post.findUnique({
where: { id },
})
}

export const createPost: MutationResolvers['createPost'] = ({ input }) => {
return db.post.create({
data: input,
})
}

export const updatePost: MutationResolvers['updatePost'] = ({ id, input }) => {
return db.post.update({
data: input,
where: { id },
})
}

export const deletePost: MutationResolvers['deletePost'] = ({ id }) => {
return db.post.delete({
where: { id },
})
}

export const Post: Partial<PostResolvers> = {
author: (_obj, gqlArgs) =>
db.post.findUnique({ where: { id: gqlArgs?.root?.id } }).author() as Author,
}


// Leave these alone
interface Bazinga {
bazinga: string
}

export const CustomExport: Bazinga = {
bazinga: 'yes'
}

export const CustomExport2: Partial<Bazinga> = {}

const HelloWorld: BazingaResolvers['HelloWorld'] = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('updateResolverTypes', () => {
it('Converts PostResolvers to Partial<PostResolvers>', async () => {
await matchTransformSnapshot('updateResolverTypes', 'default')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { API, FileInfo, TSTypeAnnotation } from 'jscodeshift'
import { Identifier, TSTypeReference } from 'jscodeshift'

const isTypeReference = (
typeAnnotation: TSTypeAnnotation['typeAnnotation']
): typeAnnotation is TSTypeReference => TSTypeReference.check(typeAnnotation)

const getTypeName = (node: TSTypeReference) => {
return Identifier.check(node.typeName) ? node.typeName.name : null
}

const isWrappedInPartial = (node: TSTypeAnnotation) => {
const typeAnnotation = node.typeAnnotation

return (
isTypeReference(typeAnnotation) && getTypeName(typeAnnotation) === 'Partial'
)
}

export default function transform(file: FileInfo, api: API) {
const j = api.jscodeshift
const ast = j(file.source)

ast.find(j.TSTypeAnnotation).forEach((path) => {
const typeAnnotationNode = path.node

if (
// If it's a MutationResolvers['x'] or QueryResolvers['x']
j.TSIndexedAccessType.check(typeAnnotationNode.typeAnnotation)
) {
return
}

if (
!isWrappedInPartial(typeAnnotationNode) &&
isTypeReference(typeAnnotationNode.typeAnnotation)
) {
const originalTypeName = getTypeName(typeAnnotationNode.typeAnnotation)

if (!originalTypeName || !originalTypeName.includes('Resolvers')) {
// Skip other type annotations!
return
}

console.log(`Wrapping ${originalTypeName} in Partial....`)

path.replace(
j.tsTypeAnnotation(
j.tsTypeReference(
j.identifier('Partial'),
j.tsTypeParameterInstantiation([
j.tsTypeReference(j.identifier(originalTypeName)),
])
)
)
)
}
})

return ast.toSource()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import path from 'path'

import fg from 'fast-glob'
import task, { TaskInnerAPI } from 'tasuku'

import getRWPaths from '../../../lib/getRWPaths'
import runTransform from '../../../lib/runTransform'

export const command = 'update-resolver-types'
export const description =
'(v2.x.x->v3.x.x) Wraps types for "relation" resolvers in the bottom of service files'

export const handler = () => {
task('Update Resolver Types', async ({ setOutput }: TaskInnerAPI) => {
await runTransform({
transformPath: path.join(__dirname, 'updateResolverTypes.js'),
// Target services written in TS only
targetPaths: fg.sync('**/*.ts', {
cwd: getRWPaths().api.services,
ignore: ['**/node_modules/**', '**/*.test.ts', '**/*.scenarios.ts'],
absolute: true,
}),
})

setOutput('All done! Run `yarn rw lint --fix` to prettify your code')
})
}
3 changes: 3 additions & 0 deletions packages/codemods/src/testUtils/matchTransformSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export const matchTransformSnapshot = async (
transformPath,
targetPaths: [tempFilePath],
parser,
options: {
verbose: true,
},
})

// Step 3: Read modified file and snapshot
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'

import task from 'tasuku'
import task, { TaskInnerAPI } from 'tasuku'

import getRWPaths from '../../../lib/getRWPaths'
import runTransform from '../../../lib/runTransform'
Expand All @@ -11,7 +11,7 @@ export const description = '(${version}->${version}) Converts world to bazinga'
export const handler = () => {
task(
'${titleName}',
async ({ setOutput }: task.TaskInnerApi) => {
async ({ setOutput }: TaskInnerApi) => {
await runTransform({
transformPath: path.join(__dirname, '${name}.js'),
// Here we know exactly which file we need to transform, but often times you won't.
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redwoodjs/core",
"version": "2.2.3",
"version": "2.2.4",
"description": "Foundational packages and config required to build RedwoodJS.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -48,10 +48,10 @@
"@babel/preset-typescript": "7.18.6",
"@babel/runtime-corejs3": "7.18.9",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.7",
"@redwoodjs/cli": "2.2.3",
"@redwoodjs/eslint-config": "2.2.3",
"@redwoodjs/internal": "2.2.3",
"@redwoodjs/testing": "2.2.3",
"@redwoodjs/cli": "2.2.4",
"@redwoodjs/eslint-config": "2.2.4",
"@redwoodjs/internal": "2.2.4",
"@redwoodjs/testing": "2.2.4",
"babel-loader": "8.2.5",
"babel-plugin-auto-import": "1.1.0",
"babel-plugin-graphql-tag": "3.3.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/create-redwood-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-redwood-app",
"version": "2.2.3",
"version": "2.2.4",
"repository": {
"type": "git",
"url": "https://github.com/redwoodjs/redwood.git",
Expand All @@ -24,8 +24,8 @@
"@babel/core": "7.18.13",
"@babel/node": "7.18.10",
"@babel/runtime-corejs3": "7.18.9",
"@redwoodjs/internal": "2.2.3",
"@redwoodjs/telemetry": "2.2.3",
"@redwoodjs/internal": "2.2.4",
"@redwoodjs/telemetry": "2.2.4",
"chalk": "4.1.2",
"check-node-version": "4.2.1",
"core-js": "3.25.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-redwood-app/template/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"@redwoodjs/api": "2.2.3",
"@redwoodjs/graphql-server": "2.2.3"
"@redwoodjs/api": "2.2.4",
"@redwoodjs/graphql-server": "2.2.4"
}
}
Loading

0 comments on commit db82751

Please sign in to comment.