How to handle static generated inputs with relay plugin? #1251
-
Hi there, Problem statementI would like to know the right approach of using relay plugin with static generated input types. DescriptionI generate Input types using static generation. For the model User {
id Int @id @default(autoincrement())
name String
email String @unique
} The generated export const UserUniqueFilter = builder.prismaWhereUnique("User", {
name: "UserUniqueFilter",
fields: () => ({
id: "Int",
email: "String",
}),
}); to use relay plugin for pagination. builder.prismaNode("User", {
name: "User",
id: { field: "id" },
fields: (t) => ({
name: t.exposeString("name", {
description: "Name of the user",
nullable: false,
}),
email: t.exposeString("email", {
description: "Email of the user",
nullable: false,
}),
}),
}); When querying user/s, the returned data is: {
"data": {
"users": {
"pageInfo": {
"endCursor": "R1BDOk46Mjk=",
"hasNextPage": false,
"hasPreviousPage": false,
"startCursor": "R1BDOk46MQ=="
},
"edges": [
{
"cursor": "R1BDOk46MQ==",
"node": {
"name": "John Doe",
"email": "[email protected]",
"id": "TGFuZ3VhZ2U6MQ=="
}
},
{
"cursor": "R1BDOk46Mg==",
"node": {
"name": "Jane Doe",
"email": "[email protected]",
"id": "TGFuZ3VhZ2U6Mg=="
}
}
]
}
}
} the returned id is global id / string, but the What should I do now? What can be the right approach to handle this?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I think this will be up to the app, and there isn't an easy answer. The prisma-utils plugin doesn't have anything built in to handle this today. I think exposing the raw ID as an Int field might be the best option for you here. When generating your schema from the DB, using the values as they exist in the DB is probably the right call. I think if you want to have a more tailored experience, you can customize the generator code to generate IDs as globalID inputs, and write a plugin that automatically decodes them to the right type, but doing this correctly isn't trivial. These kinds of edge cases are why prisma-utils and generators are marked as experimental. They work well enough for the basic cases, and aren't likely to have a lot of bugs, but they don't handle every case well. If you are interested in contributing a good solution here, I am definitely happy to help out, and advise, but I don't know any good existing solutions to this specific problem |
Beta Was this translation helpful? Give feedback.
I think this will be up to the app, and there isn't an easy answer.
The prisma-utils plugin doesn't have anything built in to handle this today.
I think exposing the raw ID as an Int field might be the best option for you here. When generating your schema from the DB, using the values as they exist in the DB is probably the right call. I think if you want to have a more tailored experience, you can customize the generator code to generate IDs as globalID inputs, and write a plugin that automatically decodes them to the right type, but doing this correctly isn't trivial.
These kinds of edge cases are why prisma-utils and generators are marked as experimental. They work well enough for the …