Toggle Menu

Accessing Cassandra with the Stargate GraphQL API

GraphQL is a powerful language for accessing data from APIs in microservice architectures. Stargate makes it easy to query Cassandra databases directly via queries expressed in GraphQL, allowing you to combine data from multiple sources with a high degree of flexibility.

What Is GraphQL?

What Is GraphQL?

GraphQL is an open-source data query and manipulation language for APIs, originally developed by Facebook in 2012 and publicly released in 2015. GraphQL allows clients to understand the data that your APIs expose and ask for only the portions they want. With GraphQL, you can create applications and services to aggregate data from multiple services or data stores.

Next concept: Why GraphQL for Cassandra?

Why GraphQL For Cassandra?

GraphQL improves upon some of the limitations of the popular REST API style by providing a typesafe, graph-based schema, where nodes represent objects and edges represent relationships. This allows clients to query and manipulate multiple data items with a single query. Queries target a single URL endpoint to perform graph traversals, which access dictionaries of values in each node. This allows clients to get tailored data in a single query, instead of multiple round trips using heavy payloads of entire records.

When the Stargate GraphQL API is added to an existing Cassandra deployment, it automatically creates HTTP endpoints that expose GraphQL queries and mutations for the objects that it finds in the database. You can also create new database tables directly via the API. The built-in GraphQL Playground servlet makes it easy to prototype your mutations and queries and experiment with new approaches.

Next concept: How to get the Stargate GraphQL API
Why GraphQL For Cassandra?
How To Get The Stargate GraphQL API

How To Get The Stargate GraphQL API

Stargate is an open-source data gateway, and is now available in DataStax Astra. If you have an Astra database, the Stargate GraphQL API is already enabled. If you don’t have a Cassandra cluster and want one, you can set up a database for free at astra.datastax.com. If you have access to your own self-hosted Cassandra cluster, see the Stargate documentation for instructions on how to install and use the GraphQL API.

Next: Try It Out

Try It Out

With the Stargate GraphQL API your applications can get exactly the data they need, directly from Cassandra. Here’s two ways you can try it yourself.

Explore The Stargate GraphQL API In DataStax Astra With This Gatsby Starter App.

Try on Astra
Astra GraphQL

Astra GraphQL

Getting started with the Stargate GraphQL API on Astra

CONTRIBUTORS

GraphQL is an open-source data query and manipulation language for APIs that allows clients to understand the data that your APIs expose and ask for only the portions they want. With GraphQL, you can create applications and services to aggregate data from multiple services or data stores. The Stargate open source project provides an API layer that allows you to expose a GraphQL API on top of any Cassandra database. Astra now offers offers a GraphQL API via Stargate, which we explore in this scenario.

Astra now offers offers a REST API via Stargate, which we explore in this scenario.

We'll use the GraphQL API to:

  • Create tables and records
  • Read records from the table
  • Update records
  • Delete records

As a prerequisite, be sure to setup an Astra account and create a Cassandra as a Service database at astra.datastax.com.

GraphQL is great stuff! Let's take a look.

Time to Complete

15

Difficulty

Intermediate

Share

More Resources

Items related to GraphQL

Stargate.io

Stargate.io

Everything you need to get up to speed on all things Stargate.

Learn More
Stargate Discord Server

Stargate Discord Server

Join our discord room to chat with the contributors and meet the community.

Start Learning
Community

Community

Learn about how you can get involved in the Stargate project.

Read More