How do I insert data to Astra DB using GraphQL API?

141 views Asked by At

I am trying to follow this youtube tutorial.

I am getting stuck at inserting the first piece of data. Ania demonstrates it at 20.46 as follows:

mutation insertGenres {
  action: insertreference_list(value: {label: "genre", value: "action"}) {
    value{
      value
    },
  }

When I try this, I get an error that says:

{
  "errors": [
    {
      "message": "Validation error of type FieldUndefined: Field 'insertreference_list' in type 'Mutation' is undefined @ 'insertreference_list'",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "extensions": {
        "classification": "ValidationError"
      }
    }
  ]
}

When I google the error, a lot of responses tell people to use mutations instead of queries - but I've started from a mutation. I would like to know how to resolve the error, but I'd also like to find the skills to improve my search strategy for finding answers.

When I look at the documentation for using GraphQL with DataStax, I see a different format to the write structure, which is as follows:

insertbook(value: bookInput!, ifNotExists: Boolean, options: UpdateOptions): bookMutationResult

It has a colon and a fragment of text after it. It also explicitly states the ifNotExists: Boolean and options. I don't know if there may have been a change to how to use DataStax since the time Ania recorded the tutorial that means it is no longer a current demonstration of how to use the tool, or if there is an answer for this and I just haven't found it yet.

1

There are 1 answers

3
Erick Ramirez On BEST ANSWER

You didn't provide details of how you've configured your Astra DB for Ania's Netflix Clone tutorial so I'm going to assume that you've named your keyspace as netflix.

It seems as though you haven't followed the instructions correctly and have missed steps. I can replicate the error you reported if I skip at least one of the steps in the tutorial.

In step 5 of the tutorial, you needed to do the following:

✅ In graphQL playground, change tab to now use graphql. Edit the end of the URl to change from system to the name of your keyspace: netflix

✅ Populate HTTP HEADER variable x-cassandra-token on the bottom of the page with your token as shown below (again !! yes this is not the same tab)

Switch tabs

In order to insert data, you need to switch to the graphql tab.

If you try to insert the data in the graphql-schema tab, you will get the error you reported.

Set keyspace

You need to update the URI of your GraphQL playground in the graphql tab to use the keyspace name netflix instead of system. For example:

https://db_id-us-west1.apps.astra.datastax.com/api/graphql/system

change to:

https://db_id-us-west1.apps.astra.datastax.com/api/graphql/netflix

If you try to insert data into the system keyspace, you will get the error you reported because the reference_list table does not exist in that keyspace. Cheers!