GraphQL queries are about starting points and traversals. From simple queries to deep filters, dive into the queries use in the message board app.
queryPost
, queryUser
, etc. A query starts
with, for example, queryPost
or by filtering to some subset of posts like
queryPost(filter: ...)
. This defines a starting set of nodes in the graph.
From there, your query traverses into the graph and returns the subgraph it
finds. You can try this out with some example queries in the next section.
queryUser
finds all
users. From those nodes, we can query the usernames as follows:
User1
sample, then you’ll get a result like the following:
data
returned is about the queryUser
query that was
executed and here’s an array of JSON about those users.
username
is an identifier, there’s also a query that finds users by
ID. To grab the data for a single user if you already know their ID, use the
following query:
User1
as the starting point, grabs the username
and
displayName
, and then traverses into the graph following the posts
edges to
get the titles of all the user’s posts.
A query could step further into the graph, finding the category of every post,
like this:
queryPost
that specify how we
want the result sorted and paginated.
@search(by: [term])
to your schema so that Dgraph Cloud would build an API for
searching posts. The nodes found as the starting points in queryPost
can be
filtered down to match only a subset of posts that have the term “graphql” in
the title by adding filter: { title: { anyofterms: "graphql" }}
to the query,
as follows:
User1
, and then traverse to their posts,
but only return those posts that have “graphql” in the title.
@search
directive in the schema. Those filters
are then available at any depth in a query, or in returning results from
mutations.