GraphQLize built on top of Lacinia, a de-facto library for implementing GraphQL APIs in Clojure.
Getting started with GraphQLize using Pedastal involves only few steps. Let's dive in.
Create a new Clojure project using deps (or leiningen) and add the GraphQLize and other dependencies.
The next step is configuring the DataSource. In this example, we are going to use Hikari Connection Pool to manage the database connection.
Make sure you are changing the above values to refer your database connection. The above example assumes that you are using the sakila database created from this JOOQ's example repository.
Creating Lacinia Schema
Then create a lacinia schema from the data source using GraphQLize.
Adding GraphQL Endpoint
The final step is adding pedestal endpoint to expose the
/graphql API. With the help of lacinia-pedestal library, we can do it with ease.
To do a test drive of this implementation, start the server
and hit the endpoint via curl.
You'll get a response like below.
GraphQL Playground and Voyager
With the GraphQL endpoint up and running, the next step is introspecting the GraphQL schema and try out some more queries.
To introspect, we are going to make use of Voyager, a tool to visualize GraphQL API as an interactive graph. To add Voyager, download this voyager.html file and put it under the resources/static directory.
Then configure pedestal to use this static directory for serving static files.
When you restart the server, the Voyager will be available at http://localhost:8080/voyager.html. A sample output would look like this.
Then to interact with the GraphQL API, let's add the GraphQL Playground. Like Voyager, download this playground.html file and put in the static directory.
This GraphQL playground will be available at http://localhost:8080/playground.html after server restart.
Congrats! You are on course to build impressive applications using GraphQLize in less time. To save yourself some more time, do refer this documentation to know more about how GraphQLize generates the GraphQL schema and the queries.
The sample code is available in this GitHub Repository.
You can also customize certain default behaviours of GraphQLize in future releases.