Skip to content

Commit

Permalink
Further fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gilgardosh committed Oct 30, 2024
1 parent 23b2922 commit 425b1a5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
6 changes: 3 additions & 3 deletions website/src/pages/tutorial/basic/08-graph-relations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ model Link {
model Comment {
id Int @id @default(autoincrement())
body String
link Link? @relation(fields: [linkId], references: [id])
linkId Int?
link Link @relation(fields: [linkId], references: [id])
linkId Int
}
```

Expand Down Expand Up @@ -460,7 +460,7 @@ type Comment {
}

type Query {
link(id: ID): Link
link(id: ID!): Link
}
```

Expand Down
10 changes: 5 additions & 5 deletions website/src/pages/tutorial/basic/09-error-handling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ string contents using a regex.

Add the following code to the `src/schema.ts` file.

```ts filename="src/schema.ts"
```ts filename="src/schema.ts" {5-10,21-26}
// ... other code ...
import { GraphQLError } from 'graphql'
import { Prisma } from '@prisma/client'
Expand Down Expand Up @@ -355,11 +355,11 @@ const resolvers = {
)
}

const comment = await context.prisma.comment
const newComment = await context.prisma.comment
.create({
data: {
body: args.body,
linkId
linkId,
body: args.body
}
})
.catch((err: unknown) => {
Expand All @@ -374,7 +374,7 @@ const resolvers = {
}
return Promise.reject(err)
})
return comment
return newComment
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions website/src/pages/tutorial/basic/10-filtering-and-pagination.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,11 @@ query {
id
description
url
postedBy {
id
name
}
}
}
```

![sample query](https://i.imgur.com/tICYe2e.png)
![sample query](https://i.imgur.com/qODhFPW.png)

## Pagination

Expand Down Expand Up @@ -131,7 +127,7 @@ Now, adjust the field resolver function implementation:

And now adjust the implementation of the `Query.feed` resolver function:

```ts filename="src/schema.ts"
```ts filename="src/schema.ts" {7,20-21}
const resolvers = {
// ... other resolvers maps ...
Query: {
Expand Down Expand Up @@ -177,7 +173,7 @@ query {
}
```

![test the pagination API ](https://i.imgur.com/XeZgSJo.png)
![test the pagination API ](https://i.imgur.com/VZzIeyJ.png)

## Pagination Field Argument Sanitization

Expand All @@ -200,7 +196,7 @@ Fetching 0 records does not make sense.

Adjust the current schema resolver implementation according to the following.

```ts filename="src/schema.ts"
```ts filename="src/schema.ts" {4-11,31-35,40}
// ... other code ...
import { GraphQLError } from 'graphql'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ const config: CodegenConfig = {
generates: {
'src/schema': defineConfig({
// (3)
resolverGeneration: 'minimal' // (4)
resolverGeneration: 'minimal', // (4)
typesPluginsConfig: {
contextType: "../context#GraphQLContext", // (5)
},
contextType: '../context#GraphQLContext' // (5)
}
})
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ export const feed: NonNullable<QueryResolvers['feed']> = async (_parent, _arg, _
It should be trivial to bring the existing logic over:

```ts filename="src/schema/base/resolvers/Query/feed.ts"
export const feed: NonNullable<QueryResolvers['feed']> = async (_parent, _arg, context) => {
export const feed: NonNullable<QueryResolvers['feed']> = async (_parent, args, context) => {
const where = args.filterNeedle
? {
OR: [
Expand Down

0 comments on commit 425b1a5

Please sign in to comment.