I’ve done a lot of work with both Prisma and Absinthe. Here’s my take.
For quick background, Prisma is built on Scala/Sangria and uses MySQL, all Dockerized. They will soon provide adapters for Postgres, Mongo, and Elastic Search.
Prisma abstracts the database layer into a GraphQL API. You still need a GraphQL server. If you’ve worked with GraphQL schema stitching before, it really is schema stitching a database GraphQL application into your main GraphQL application.
It has two main advantages. The first is database migrations. For instance, when you declare a two SDL types, e.g.
type Post {
id: ID!
title: String
likes: Int
comments: [Comment]!
...
}
type Comment {
...
text: String!
post: Post!
}
Prisma infers the one to many relationship and migrates the data base accordingly! Awesome.
Second, it generates much of the GraphQL boilerplate. For instance, for the above types, it will automatically generate a PostsConnection
type. Simply import the type (e.g. graphql-import
package) and you’re off and running with GraphQL connections. Hand wringing that in Absinthe (or any other server implementation) can take some time. And it generates all CRUD functions, e.g. updatePost.
For server packages, Absinthe and Elixir can’t be beat. However, I typically don’t like ORMs and tend to fight against them. I kept butting heads with Ecto for various reasons – some better than others. If you are comfortable with Ecto, I’d say go with Absinthe.
The holy grail is an Elixir graphql binding package. A graphql binding introspects a schema and generates operations based on that schema. For instance, on Node Prisma has a prisma-binding
package. You give the Prisma endpoint to the binding package, and then you have an object with graphql functions, e.g.
Prisma generates
type Posts(where: PostWhereInput, orderBy: PostOrderByInput ...) {
...
}
input PostWhereInput {
...
title: String!
title_contains: String!
title_starts_with: String!
title_in: [String!]
...
likes_gte: Int
likes_lte: Int
...
}
And then in your resolver…
const result = await db.query.posts({ where: { comments: { text_contains: "Elixir" } } })
I’m developing with Node/Prisma now, but I look forward to a GraphQL binding package for Elixir and an SDL types importing mechanism, if one doesn’t already exist. (Making either are way above my pay grade to develop!)
Hopefully that helps!