Dark Mode

In order to use the GraphQL API, you must create schema that defines the tablesthat will store the data, in a keyspace that you have defined with the DataStax Astra DB UI.Tables consist of columns that have a defined data type. Multiple tables are containedin a keyspace, but a table cannot be contained in multiple keyspaces.

Prerequisites

Use the application token you generatedto create schema in your keyspace using the GraphQL playground.

Creating a table

You can create a table using a mutation in /graphql-schema .In the following example, products is the table name.The table columns are name , description , price , and created .

+A special column, partitionKey , defines the outermost grouping of data, similar to a schema in a relational database.In this example, we'll use the name column to group our data.

In this example, create two tables by executing the following mutation, in eitherthe GraphQL playground, or by executing the cURL command in a terminal.The first table, book includes the table columns title and author .A special column or columns, partitionKeys , defines the outermost grouping of data,similar to a schema in a relational database.For book , the title column groups the data.Another special column or columns, clusteringKeys can sort the data within atable.For book , the author column sorts the data.

It is worth noting that one mutation is used to create two tables.Information about partition keys and clustering keys can be found in theCQL reference.

The second table, reader , also defines a column using the UDT that wascreated above.

Data types

Tables can be created with an option ifNotExists .They can also be created with collections (set, list, map), tuples, and UDTs.

IF NOT EXISTS option

A table can be created with an option ifNotExists that will only create thetable if it does not already exist:

One of these tables includes creating a column with the data type LIST , an orderedcollection of text values.

Collection (set, list, map) columns

Including a collection in a table has a couple of extra parts:

This example shows a map. A previous example shows a list.In the next example, a set will be used.

Adding columns to table schema

If you need to add more attributes to something you are storing in a table, youcan add one or more columns:

Checking that keyspaces and tables exist

To check if a keyspace, tables, or particular table columns exist, execute aGraphQL query:

For keyspaces and tables:

And for tables:

Because these queries are named, the GraphQL playground will allow you to selectwhich query to run. The first query will return information about the keyspace library and the tables within it. The second query will return just informationabout the tables in that keyspace.