Graphen Django: Batch requests should receive a list, but received {'query': XXX}

635 views Asked by At

I have enabled the batch query processing functionality in Graphene-Django by adding batch=True to the .as_view(...) method as,

urlpatterns = [
    # other URL patterns,
    path('graphql/', CustomGraphQLView.as_view(schema=schema, batch=True), name='graphql')
]

After that, I sent the request (see below screenshot) with a query to the server using Postman client, but got an error

GraphQL Query

{
  musicians {
    id
    name
  }
}

Error Response

{ "errors": [ { "message": "Batch requests should receive a list, but received {'query': 'bla bla'}" } ] }

Postman Screenshot

request screenshot

Question

  1. What is the proper way to send the GraphQL batch requests to Graphene-Django?
  2. How can I send GraphQL batch requests to Graphene-Django using Postman client?
1

There are 1 answers

0
JPG On

The Graphene-Django expects the queries as a list of dicts (or JSON Array of JSON Objects).

So you need to build a payload as,

[
    {
        "query": "{musicians{id}}"
    },
    {
        "query": "{musicians{name}}"
    },
    {
        "query": "{musicians{id,name,}}"
    }
]

Make sure that, the request should be sent as raw JSON from the POSTMAN client (or any non-GraphQL client)

Result Screenshot

enter image description here