I am new to pothos and graphql. i have some problems related to query. #1078
Answered
by
MinhNguyen5199
MinhNguyen5199
asked this question in
Q&A
-
builder.queryField("find_order_items", (t) =>
t.prismaField({
type: ["order_items"],
resolve: (query, __parent, __args, _ctx, _info) =>
prisma.order_items.findMany({
...query,
where: {
user_id: "55bedbd6-d5db-4af8-9502-b505c8063734",
`what go in user_id, so I can query order_items based on the user_id `
}
}),
})
); const listOrderItems = gql`
query ListOrderItems($user_id: String){
find_order_items(user_id: $user_id ){
id
quantity
}
} is the code above correct to query order_items based on user_id ? const {data, loading, error} = useQuery(listOrderItems, {variables: {user_id: minh} }) |
Beta Was this translation helpful? Give feedback.
Answered by
MinhNguyen5199
Nov 1, 2023
Replies: 1 comment 2 replies
-
i finally find and answer for my problem. builder.queryField("order_items", (t) =>
t.prismaField({
type: ["order_items"], // Assuming "Product" is the name of your product model
args: { user_id: t.arg.string() },
resolve: async (query, _parent, args, _ctx, _info) => {
const { user_id } = args;
return await prisma.order_items.findMany({
...query,
where: {
user_id: {
contains: user_id? user_id : "",
mode: "insensitive", // This makes the search case-insensitive
},
},
});
},
})
); |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
hayes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i finally find and answer for my problem.