Prisma + GraphQL. Project Setup Pt2 : Apollo Server & Client.
--
So, the first part concluded with deployment of Prisma, and now it’s time to set up the Apollo Server to run on the backend, and Apollo Client on the FrontEnd.
Setting Up Apollo Server 2
Let’s start with installing the required dependencies. We’re going to run the npm install command from our backend folder.
npm i apollo-server graphql graphql-import prisma-binding
- apollo-server — the core library for the server itself.
- graphql — so that we can build our queries and mutations
- grapql-import - in case if you decide to split your schema definition into multiple files,
graphql-import
package is there to help you importing & exporting schema definitions in GraphQL SDL (a.k.a GraphQL modules). It is also important to notice that it currently uses a custom syntax based on SDL comments.
Prisma bindings vs Prisma client
What are GraphQL Bindings?
GraphQL bindings are functions in your programming language that let you send queries, mutations and subscriptions to a GraphQL API. The functions are generated based on a GraphQL schema and mirror the GraphQL API.
Essentially, GraphQL bindings:
- enable accessing a GrapQL API from a variety of programming languages;
- provide a “GraphQL ORM” layer, which interfaces with your Prisma through a simplified resolvers.
- You can read more about it here.
To understand it better we can refer to the image below:
- Design a GraphQL query (on the left)
- Implement the resolvers, which will in turn construct corresponding queries to the Prisma API using GraphQL bindings (on the right).
How does code generation work with GraphQL bindings? The Prisma GraphQL bindings are generated based on the Prisma data model.
The Prisma client and Prisma…