Skip to content

Commit

Permalink
[drizzle] Fix t.drizzleField for list types
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Sep 10, 2024
1 parent c76853f commit 6dbe790
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-moles-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pothos/plugin-drizzle": patch
---

fix drizzleField list types
27 changes: 19 additions & 8 deletions packages/plugin-drizzle/src/global-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,25 @@ declare global {
Param extends [DrizzleRef<any, infer T>]
? T & keyof Types['DrizzleRelationSchema']
: never,
Type extends TypeParam<Types> = ObjectRef<
Types,
BuildQueryResult<
Types['DrizzleRelationSchema'],
Types['DrizzleRelationSchema'][Table],
true
>
>,
Type extends TypeParam<Types> = Param extends [unknown]
? [
ObjectRef<
Types,
BuildQueryResult<
Types['DrizzleRelationSchema'],
Types['DrizzleRelationSchema'][Table],
true
>
>,
]
: ObjectRef<
Types,
BuildQueryResult<
Types['DrizzleRelationSchema'],
Types['DrizzleRelationSchema'][Table],
true
>
>,
>(
options: DrizzleFieldOptions<
Types,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Query {
posts(after: String, before: String, category: String, first: Int, last: Int): QueryPostsConnection
user(id: ID!): User
userWithInput(input: QueryUserWithInputInput!): User
users(id: ID!): [User!]
}
type QueryPostsConnection {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-drizzle/tests/example/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type Query {
posts(after: String, before: String, category: String, first: Int, last: Int): QueryPostsConnection
user(id: ID!): User
userWithInput(input: QueryUserWithInputInput!): User
users(id: ID!): [User!]
}

type QueryPostsConnection {
Expand Down
13 changes: 13 additions & 0 deletions packages/plugin-drizzle/tests/example/schema/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ builder.queryType({
);
},
}),
users: t.drizzleField({
type: ['users'],
args: {
id: t.arg.globalID({ required: true, for: User }),
},
resolve: (query, _root, { id }) => {
return db.query.users.findMany(
query({
where: (user, { eq }) => eq(user.id, id.id.id),
}),
);
},
}),
userWithInput: t.drizzleFieldWithInput({
type: 'users',
input: {
Expand Down

0 comments on commit 6dbe790

Please sign in to comment.