Get the structure for GraphQL requests and responses, how to enable compression for them, and configuration options for extensions
Header | Optionality | Value |
---|---|---|
Content-Type | mandatory | application/graphql or application/json |
Content-Encoding | optional | gzip to send compressed data |
Accept-Encoding | optional | gzip to enabled data compression on response |
X-Dgraph-AccessToken | if ACL is enabled | pass the access token you got in the login response to access predicates protected by an ACL |
X-Auth-Token | if anonymous access is turned off | admin key or client key |
header as set in Dgraph.Authorization | if GraphQL Dgraph.Authorization is set | valid JWT used by @auth directives |
anonymous access
and Dgraph.Authorization
.application/graphql
must have
a POST body content as a GraphQL query string. For example, the following is a
valid POST body for a query:
application/json
must have a
POST body in the following JSON format:
query
,
mutation
, or subscription
. If a request only has one operation, then it can
be unnamed like the following:
query
operation running the queries getTask
and getUser
:
getTaskAndUser
and completedTasks
.
completedTasks
operation executes the second query:
query
or mutation
and are passed like
arguments to a function and begin with $
.
postData
fragment that can be used
with any Post
object:
allCharacters
query returns a list of Character
objects. Since Human
and Droid
implements the Character
interface, the fields in the result would
be returned according to the type of object.
Result
HTTP GET
operation.
\GET requests must be sent in the following format. The query, variables, and
operation are sent as URL-encoded query parameters in the URL.
query
is mandatoryvariables
is only required if the query contains GraphQL variables.operationName
is only required if there are multiple operations in the
query; in which case, operations must also be named."data"
, "errors"
, or
"extensions"
following the GraphQL specification. They follow the following
formats.
Successful queries are in the following format:
"message"
field that
describes the error and optionally has a "locations"
array to list the
specific line and column number of the request that points to the error
described. For example, hereβs a possible error for the following query, where
getTask
needs to have an id
specified as input:
Query:
null
values for non-nullable fields (such as String!
) cause
error propagation to parent fields.
In short, the GraphQL value completion and error propagation mean the following.
!
) can return null
in the JSON
response.!
) Dgraph never returns null for
that field.name: String!
) causes the author to result in null, and a null
author causes the post (author: Author!
) to result in null.friends [Author]
), can result in nulls inside the result list.friends [Author!]
and would cause further error propagation for
friends [Author!]!
.[]
, not null
, regardless of whether it is nullable. For example, given
a schema for an author with posts: [Post!]!
, if an author hasnβt posted
anything and we queried for that author, the result for the posts field would be
posts: []
.
A list can, however, result in null due to GraphQL error propagation. For
example, if the definition is posts: [Post!]
, and we queried for an author who
has a list of posts. If one of those posts happened to have a null title (title
is non-nullable title: String!
), then that post would evaluate to null, the
posts
list canβt contain nulls and so the list reduces to null.
"touched_uids"
: The number of nodes that were touched to satisfy the
request. This is a good metric to gauge the complexity of the query."tracing"
: Displays performance tracing data in Apollo
Tracing format. This includes the duration of the whole query
and the duration of each operation."dql_query"
: Optional, displays the translated DQL query Dgraph composed.
This is only output when the GraphQL debug superflag
(--graphql "debug=true;")
is set.--graphql
superflagβs extensions
option to
false (--graphql extensions=false
) when running Dgraph Alpha.