Anyone here migrate from Graphcool to Prisma? I g...
# orm-help
p
Anyone here migrate from Graphcool to Prisma? I got my Prisma server up and running but already have clients deployed to production using the old Graphcool server. Any way to easily backport certain schemas into Prisma? For example:
allUsers
->
users
or
updateUser(*stuff*)
->
updateUser(data: *stuff*)
v
Yeah, this is a pain. Are your clients under your control? If so, might be better to take a one-time forced upgrade of all the clients … perhaps via keeping both the graph.cool and prisma end points parallel while your users upgrade? With Prisma, you can expose whatever schema you want. But you can also restrict a lot more and expose only what the clients need, etc. Just some thoughts.
p
@virtualirfan Yeah, they're under my control and I thought about doing that but those are multiple large scale projects and I'm on a strict deadline. One advantage is that the clients aren't connecting to Graphcool directly but rather a gateway server I made for them that acts as a proxy to Graphcool (I needed it for custom auth and Apollo Engine). I was hoping I'd just be able to point the proxy server to my Prisma endpoint to avoid updates. I may be able to create custom bindings the same way I did for Apollo Engine support, but that'd be a long and tedious process with my large schema.
v
Unless your clients used
relay
, you might be able to write a migration script that creates the handlers using prisma bindings with
forwardTo
where appropriate and then query calls otherwise filling in the
data:
and
where:
fields. IOW, use the entire generated schema file from graph.cool as your new prisma schema and try to autogen the handlers.
p
@virtualirfan That could work, thanks! Looking into
forwardTo
made me find this post: https://github.com/prismagraphql/prisma-binding/issues/48 Given that I'm already using custom resolvers, I may be able to do things this way. It could work nicely for queries, but mutations might be problematic as I'd essentially be overriding them with themselves. (ex:
updateArticle()
delegates to
updateArticle(data)
which may end up calling itself again and never end) I'll give it a try! How would I autogen the handlers on Prisma? I just started learning about Prisma last week.
v
A custom resolver for
updateArticle()
in the application's schema would call the
updateArticle(data: args)
in the Prisma service so there shouldn't be a loop. Re: autogen, I figured you'd write a shell script or choose your favorite scripting language and iterate over all the types in the original graph.cool schema and generate custom resolvers.
Are you using subscriptions?
p
@virtualirfan Oh really? That's convenient. I'm using
mergeSchemas
from the
graphql-tools
package to create resolvers on my API Gateway. I wonder if that'll work this way. Luckily, no. I plan on doing so in the future, but I'm migrating to Prisma first to avoid future migration nightmares such as this. 🙂
In case anyone is interested, I ended up resolving this by mutating mutation queries directly in the request body before it gets processed by Prisma (using Express):
Copy code
if (req.body && req.body.query && !req.body.query.includes("(data:")) {
	req.body.query = req.body.query.replace(/(mutation{\D*\()(.*)(?=\))/g, '$1data: {$2}');
}
It's dirty, but I only need it temporarily until we update our clients to use the correct syntax.