Back

Query Batching: batch many documents deletes operations in one GraphQL request

  • 0
  • Databases
  • GraphQL
Nour
9 Nov, 2023, 07:52

I attempted to batch multiple document deletion operations into a single GraphQL request, as shown in the following code:

TL;DR
The user is experiencing an issue where only one document is being deleted and returned in the response when attempting to batch multiple document deletion operations in a GraphQL request. They suspect that the regular `deleteDocument()` function may be the cause since it doesn't return anything. They would like to know how to solve the issue. Solution: It is suggested to use the correct syntax for multi-line code and surround it with triple backticks. To address the issue, the user can create a list of queries for each document to be deleted and then execute the GraphQL mutation for all queries at once. Here is an example code snippet: ```python queries =
Nour
9 Nov, 2023, 07:52
TypeScript
queries = []
count = 0

for message_id in body["delete"]:
    temp = {}
    count += 1
    query = (
        f"mutation DeleteDocument{count}"
        + """($databaseId: String!, $collectionId: String!, $documentId: String!){
                databasesDeleteDocument(
                    databaseId: $databaseId,
                    collectionId: $collectionId,
                    documentId: $documentId
                ) {
                        status
                }
        }
            """
    )
    variables = {
        "databaseId": "651f17af2552b5dc8126",
        "collectionId": "651f17d6a1d4cdf7c76a",
        "documentId": "{}".format(message_id),
    }

    temp["query"] = query
    temp["operationName"] = f"DeleteDocument{count}"
    temp["variables"] = variables
    queries.append(temp)
result = graphql.mutation(queries)
print(f"result = > {result}")
for re in result:
    print(re)```
Nour
9 Nov, 2023, 07:52

However, it only deleted one document and returned a single response. Is this issue caused by the Appwrite GraphQL Delete operation? I ask because I tried a different operation, like batching many create operations, and it worked. So, what is the problem and how can I solve it in the GraphQL batching?

Drake
9 Nov, 2023, 07:53

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

Nour
12 Nov, 2023, 07:02

??

Drake
12 Nov, 2023, 22:07

What exactly was the full response?

Nour
13 Nov, 2023, 07:50

It just return one response of deleting one message only: b''

Drake
13 Nov, 2023, 21:25

hmmmm this is sort of expected....the regular deleteDocument() doesn't return anything

Nour
14 Nov, 2023, 07:50

Does deleting a document disrupt the GraphQL request, and is this the reason for only deleting one document only?

Nour
20 Nov, 2023, 12:40

??

Haimantika
20 Nov, 2023, 13:28

As far as I know, it shouldn't

Nour
20 Nov, 2023, 13:34

So why does it delete only one document and return a single response for all queries?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more