-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0b09f2
commit 398010e
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const schema = gql` | ||
type Comment { | ||
id: Int! | ||
name: String! | ||
body: String! | ||
post: Post! | ||
postId: Int! | ||
createdAt: DateTime! | ||
} | ||
type Query { | ||
comments: [Comment!]! @requireAuth | ||
} | ||
input CreateCommentInput { | ||
name: String! | ||
body: String! | ||
postId: Int! | ||
} | ||
input UpdateCommentInput { | ||
name: String | ||
body: String | ||
postId: Int | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Prisma, Comment } from '@prisma/client' | ||
import type { ScenarioData } from '@redwoodjs/testing/api' | ||
|
||
export const standard = defineScenario<Prisma.CommentCreateArgs>({ | ||
comment: { | ||
one: { | ||
data: { | ||
name: 'String', | ||
body: 'String', | ||
post: { create: { title: 'String', body: 'String' } }, | ||
}, | ||
}, | ||
two: { | ||
data: { | ||
name: 'String', | ||
body: 'String', | ||
post: { create: { title: 'String', body: 'String' } }, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
export type StandardScenario = ScenarioData<Comment, 'comment'> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Comment } from '@prisma/client' | ||
|
||
import { comments } from './comments' | ||
import type { StandardScenario } from './comments.scenarios' | ||
|
||
// Generated boilerplate tests do not account for all circumstances | ||
// and can fail without adjustments, e.g. Float and DateTime types. | ||
// Please refer to the RedwoodJS Testing Docs: | ||
// https://redwoodjs.com/docs/testing#testing-services | ||
// https://redwoodjs.com/docs/testing#jest-expect-type-considerations | ||
|
||
describe('comments', () => { | ||
scenario('returns all comments', async (scenario: StandardScenario) => { | ||
const result = await comments() | ||
|
||
expect(result.length).toEqual(Object.keys(scenario.comment).length) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { QueryResolvers, CommentRelationResolvers } from 'types/graphql' | ||
|
||
import { db } from 'src/lib/db' | ||
|
||
export const comments: QueryResolvers['comments'] = () => { | ||
return db.comment.findMany() | ||
} | ||
|
||
export const comment: QueryResolvers['comment'] = ({ id }) => { | ||
return db.comment.findUnique({ | ||
where: { id }, | ||
}) | ||
} | ||
|
||
export const Comment: CommentRelationResolvers = { | ||
post: (_obj, { root }) => { | ||
return db.comment.findUnique({ where: { id: root?.id } }).post() | ||
}, | ||
} |