Recursive input prisma ID type issue #741
Unanswered
thuperthecret2
asked this question in
Q&A
Replies: 1 comment
-
I think this should be easy to fix with a minor modification: When Pothos was first released, it was common for servers to not convert numeric IDs to strings, while this is now fairly standard, the default setting in Pothos has not changed yet, but you can configure Pothos to undersand that IDs will always be strings (this will be the default in the next major version). const builder = new SchemaBuilder<{
Scalars: {
// Define the ID scalar as being a string when used as an input
ID: { Input: 'string', Output: 'string' | number }
}
}>({...yourOptions });
interface UserWhereInputShape {
id?: string
name_contains?: string
email_contains?: string
name_starts_with?: string
isSuspended?: boolean
isDeleted?: boolean
AND?: UserWhereInputShape[]
OR?: UserWhereInputShape[]
NOT?: UserWhereInputShape[]
}
const UserWhereInput = builder
.inputRef<UserWhereInputShape>('UserWhereInput')
.implement({
fields: (t) => ({
// change this to use an ID
id: t.id(),
name: t.string(),
email: t.string(),
isSuspended: t.boolean(),
isDeleted: t.boolean(),
// The implementation is due to recursive inputs below if needed, it's a good example
AND: t.field({
type: [UserWhereInput],
}),
OR: t.field({
type: [UserWhereInput],
}),
NOT: t.field({
type: [UserWhereInput],
}),
}),
})
builder.queryField('user', (t) =>
t.prismaField({
type: 'User',
authScopes: {
isAuthenticated: true,
},
nullable: true,
args: {
id: t.arg.id({ required: true }),
},
resolve: async (query, root, args, ctx, info) => {
// Simulate slow response, test cache
// await new Promise((resolve) => setTimeout(resolve, 5000))
return prisma.user.findUnique({
...query,
where: {
id: args.id as string,
},
})
},
}),
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm having a weird little issue, I'm trying to add the AND OR NOT recursive inputs to a prisma where input, but I'm getting a
string
type in the graphql output instead of ID (which I want as a cuid string) because I can't useid?: id
in the UserWhereInputShape.Is there an easy way to make these with recursive AND OR NOT for prisma and still keep the ID type on id fields? Also GraphQL ID type should be
string
, notstring | number
. I believe according to the GraphQL spec it should be serialized as a string.The following is is the only way I got it to work so far but again it leads to string types in the graphql instead of ID:
Beta Was this translation helpful? Give feedback.
All reactions