prismagraphql / prisma
- четверг, 17 мая 2018 г. в 00:18:01
Scala
⚡️ Prisma turns your database into a realtime GraphQL API
Website • Docs • Blog • Forum • Slack • Twitter • OSS • Learn
Prisma is a performant open-source GraphQL ORM-like layer doing the heavy lifting in your GraphQL server. It turns your database into a GraphQL API which can be consumed by your resolvers via GraphQL bindings.
Prisma's auto-generated GraphQL API provides powerful abstractions and modular building blocks to develop flexible and scalable GraphQL backends:
Watch this 3-min tutorial or follow the steps below to get started with Prisma.
npm install -g prisma
Run the following command to create the files you need for a new Prisma service.
prisma init hello-world
Then select the Demo server (hosted in Prisma Cloud) and follow the instructions of the interactive CLI prompt.
Instead of using a Demo server, you can also setup a Prisma server that is connected to your own database. Note that this requires Docker.
To do so, run prisma init
as shown above and follow the interactive CLI prompts to choose your own database setup:
Once the command has finished, you need to run docker-compose up -d
to start the Prisma server.
Edit datamodel.graphql
to define your data model using GraphQL SDL:
type Tweet {
id: ID! @unique
createdAt: DateTime!
text: String!
owner: User!
}
type User {
id: ID! @unique
handle: String! @unique
name: String!
tweets: [Tweet!]!
}
To deploy your service, run the following command:
prisma deploy
Run the following command to open a GraphQL Playground and start sending queries and mutations:
prisma playground
Create a new user:
mutation {
createUser(
data: {
name: "Alice"
handle: "alice"
}
) {
id
}
}
Query all users and their tweets:
query {
users {
id
name
tweets {
id
createdAt
text
}
}
}
Create a new tweet for a user:
Replace the
__USER_ID__
placeholder with theid
of an actualUser
mutation {
createTweet(
data: {
text: "Prisma makes building GraphQL servers fun & easy"
owner: {
connect: {
id: "__USER_ID__"
}
}
}
) {
id
createdAt
owner {
name
}
}
}
You can now connect to Prisma's GraphQL API, select what you would like to do next:
Collection of Prisma example projects
You can also check the AirBnB clone example we built as a fully-featured demo app for Prisma.
Prisma takes the role of a data access layer in your backend architecture by connecting your API server to your databases. It enables a layered architecture which leads to better separation of concerns and improves maintainability of the entire backend.
Acting as a GraphQL database proxy, Prisma provides a GraphQL-based abstraction for your databases enabling you to read and write data with GraphQL queries and mutations. Using Prisma bindings, you can access Prisma's GraphQL API from your programming language.
Prisma servers run as standalone processes which allows for them to be scaled independently from your API server.
Prisma provides a mapping from your API to your database. In that sense, it solves similar problems as conventional ORMs. The big difference between Prisma and other ORMs is the way how the mapping is implemented.
Prisma takes a radically different approach which avoids the shortcomings and limitations commonly experienced with ORMs. The core idea is that Prisma turns your database into a GraphQL API which is then consumed by your API server (via GraphQL binding). While this makes Prisma particularly well-suited for building GraphQL servers, it can definetely be used in other contexts as well.
Here is how Prisma compares to conventional ORMs:
Database connectors provide the link between Prisma and the underlying database.
You can connect the following databases to Prisma already:
More database connectors will follow.
If you are interested to participate in the preview for one of the following connectors, please reach out in our Slack.
We are still collecting use cases and feedback for the API design and feature set of the following connectors:
Join the discussion or contribute to influence which we'll work on next!
The most important component in Prisma is the GraphQL API:
Prisma's auto-generated GraphQL APIs are fully compatible with the OpenCRUD standard.
Prisma has a community of thousands of amazing developers and contributors. Welcome, please join us!
Contributions are welcome and extremely helpful
Releases are separated into two channels - the stable and unstable channel.
The stable channel is released every two weeks, incrementing the minor version number. Irregular releases in between minor releases can occur and increment the patch version.
The unstable channel is released with every commit to master and therefore gives access to features and bug fixes before the stable release. You can find more information about running the Prisma on the unstable channel here.