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

RSC: test-project EmptyUser 'use client' cell #10007

Merged
merged 2 commits into from
Feb 14, 2024
Merged
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
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE "EmptyUser" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"email" TEXT NOT NULL,
"name" TEXT
);

-- CreateIndex
CREATE UNIQUE INDEX "EmptyUser_email_key" ON "EmptyUser"("email");
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ model UserExample {
email String @unique
name String?
}

model EmptyUser {
id Int @id @default(autoincrement())
email String @unique
name String?
}
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": "7.0.0-canary.983",
"@redwoodjs/graphql-server": "7.0.0-canary.983"
"@redwoodjs/api": "7.0.0-canary.993",
"@redwoodjs/graphql-server": "7.0.0-canary.993"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const schema = gql`
type EmptyUser {
id: Int!
email: String!
name: String
}

type Query {
emptyUsers: [EmptyUser!]! @requireAuth
emptyUser(id: Int!): EmptyUser @requireAuth
}

input CreateEmptyUserInput {
email: String!
name: String
}

input UpdateEmptyUserInput {
email: String
name: String
}

type Mutation {
createEmptyUser(input: CreateEmptyUserInput!): EmptyUser! @requireAuth
updateEmptyUser(id: Int!, input: UpdateEmptyUserInput!): EmptyUser!
@requireAuth
deleteEmptyUser(id: Int!): EmptyUser! @requireAuth
}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Prisma, EmptyUser } from '@prisma/client'
import type { ScenarioData } from '@redwoodjs/testing/api'

export const standard = defineScenario<Prisma.EmptyUserCreateArgs>({
emptyUser: {
one: { data: { email: 'String5770021' } },
two: { data: { email: 'String5278315' } },
},
})

export type StandardScenario = ScenarioData<EmptyUser, 'emptyUser'>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { EmptyUser } from '@prisma/client'

import {
emptyUsers,
emptyUser,
createEmptyUser,
updateEmptyUser,
deleteEmptyUser,
} from './emptyUsers'
import type { StandardScenario } from './emptyUsers.scenarios'

// Generated boilerplate tests do not account for all circumstances
// and can fail without adjustments, e.g. Float.
// Please refer to the RedwoodJS Testing Docs:
// https://redwoodjs.com/docs/testing#testing-services
// https://redwoodjs.com/docs/testing#jest-expect-type-considerations

describe('emptyUsers', () => {
scenario('returns all emptyUsers', async (scenario: StandardScenario) => {
const result = await emptyUsers()

expect(result.length).toEqual(Object.keys(scenario.emptyUser).length)
})

scenario('returns a single emptyUser', async (scenario: StandardScenario) => {
const result = await emptyUser({ id: scenario.emptyUser.one.id })

expect(result).toEqual(scenario.emptyUser.one)
})

scenario('creates a emptyUser', async () => {
const result = await createEmptyUser({
input: { email: 'String8450568' },
})

expect(result.email).toEqual('String8450568')
})

scenario('updates a emptyUser', async (scenario: StandardScenario) => {
const original = (await emptyUser({
id: scenario.emptyUser.one.id,
})) as EmptyUser
const result = await updateEmptyUser({
id: original.id,
input: { email: 'String82168002' },
})

expect(result.email).toEqual('String82168002')
})

scenario('deletes a emptyUser', async (scenario: StandardScenario) => {
const original = (await deleteEmptyUser({
id: scenario.emptyUser.one.id,
})) as EmptyUser
const result = await emptyUser({ id: original.id })

expect(result).toEqual(null)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { QueryResolvers, MutationResolvers } from 'types/graphql'

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

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

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

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

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

export const deleteEmptyUser: MutationResolvers['deleteEmptyUser'] = ({
id,
}) => {
return db.emptyUser.delete({
where: { id },
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
]
},
"devDependencies": {
"@redwoodjs/core": "7.0.0-canary.983",
"@redwoodjs/project-config": "7.0.0-canary.983"
"@redwoodjs/core": "7.0.0-canary.993",
"@redwoodjs/project-config": "7.0.0-canary.993"
},
"eslintConfig": {
"extends": "@redwoodjs/eslint-config",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
},
"dependencies": {
"@apollo/experimental-nextjs-app-support": "0.0.0-commit-b8a73fe",
"@redwoodjs/forms": "7.0.0-canary.983",
"@redwoodjs/router": "7.0.0-canary.983",
"@redwoodjs/web": "7.0.0-canary.983",
"@redwoodjs/forms": "7.0.0-canary.993",
"@redwoodjs/router": "7.0.0-canary.993",
"@redwoodjs/web": "7.0.0-canary.993",
"@tobbe.dev/rsc-test": "0.0.3",
"client-only": "0.0.1",
"react": "0.0.0-experimental-e5205658f-20230913",
"react-dom": "0.0.0-experimental-e5205658f-20230913",
"server-only": "0.0.1"
},
"devDependencies": {
"@redwoodjs/vite": "7.0.0-canary.983",
"@redwoodjs/vite": "7.0.0-canary.993",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ const AboutPage = serve('AboutPage')
const HomePage = serve('HomePage')
const UserExampleUserExamplesPage = serve('UserExampleUserExamplesPage')
const UserExampleNewUserExamplePage = serve('UserExampleNewUserExamplePage')
const EmptyUserEmptyUsersPage = serve('EmptyUserEmptyUsersPage')
const EmptyUserNewEmptyUserPage = serve('EmptyUserNewEmptyUserPage')

const Routes = () => {
return (
<Router>
<Set wrap={ScaffoldLayout} title="EmptyUsers" titleTo="emptyUsers" buttonLabel="New EmptyUser" buttonTo="newEmptyUser">
<Route path="/empty-users/new" page={EmptyUserNewEmptyUserPage} name="newEmptyUser" />
{/* <Route path="/empty-users/{id:Int}/edit" page={EmptyUserEditEmptyUserPage} name="editEmptyUser" />
<Route path="/empty-users/{id:Int}" page={EmptyUserEmptyUserPage} name="emptyUser" /> */}
<Route path="/empty-users" page={EmptyUserEmptyUsersPage} name="emptyUsers" />
</Set>
<Set wrap={ScaffoldLayout} title="UserExamples" titleTo="userExamples" buttonLabel="New UserExample" buttonTo="newUserExample">
<Route path="/user-examples/new" page={UserExampleNewUserExamplePage} name="newUserExample" />
{/* <Route path="/user-examples/{id:Int}/edit" page={UserExampleEditUserExamplePage} name="editUserExample" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import type {
EditEmptyUserById,
UpdateEmptyUserInput,
UpdateEmptyUserMutationVariables,
} from 'types/graphql'

import { navigate, routes } from '@redwoodjs/router'
import type {
CellSuccessProps,
CellFailureProps,
TypedDocumentNode,
} from '@redwoodjs/web'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'

import EmptyUserForm from 'src/components/EmptyUser/EmptyUserForm'

export const QUERY: TypedDocumentNode<EditEmptyUserById> = gql`
query EditEmptyUserById($id: Int!) {
emptyUser: emptyUser(id: $id) {
id
email
name
}
}
`

const UPDATE_EMPTY_USER_MUTATION: TypedDocumentNode<
EditEmptyUserById,
UpdateEmptyUserMutationVariables
> = gql`
mutation UpdateEmptyUserMutation($id: Int!, $input: UpdateEmptyUserInput!) {
updateEmptyUser(id: $id, input: $input) {
id
email
name
}
}
`

export const Loading = () => <div>Loading...</div>

export const Failure = ({ error }: CellFailureProps) => (
<div className="rw-cell-error">{error?.message}</div>
)

export const Success = ({ emptyUser }: CellSuccessProps<EditEmptyUserById>) => {
const [updateEmptyUser, { loading, error }] = useMutation(
UPDATE_EMPTY_USER_MUTATION,
{
onCompleted: () => {
toast.success('EmptyUser updated')
navigate(routes.emptyUsers())
},
onError: (error) => {
toast.error(error.message)
},
}
)

const onSave = (
input: UpdateEmptyUserInput,
id: EditEmptyUserById['emptyUser']['id']
) => {
updateEmptyUser({ variables: { id, input } })
}

return (
<div className="rw-segment">
<header className="rw-segment-header">
<h2 className="rw-heading rw-heading-secondary">
Edit EmptyUser {emptyUser?.id}
</h2>
</header>
<div className="rw-segment-main">
<EmptyUserForm
emptyUser={emptyUser}
onSave={onSave}
error={error}
loading={loading}
/>
</div>
</div>
)
}
Loading
Loading