Level up your GraphQL + GraphDB knowledge - Register free for Dgraph Day
To optimize your experience, the interactive tutorial is only available on desktop.

Dgraph GraphQL Tour


Exercise: Integrating existing data

In previous lessons, you added a new schema and loaded some company data. But, what about integrating the pre-existing dataset about friends and their pets with the dataset extension that includes companies?

If we try to reference an existing company in a mutation by name with our current schema, we will instead create a new Company node, as you saw in a previous lesson. The generated GraphQL API makes it very easy to search for a node to update, and update the node linking to existing or new nodes.

The example mutation there searches for nodes of type Person by their xid and updates those nodes by setting edges to existing people, new people, and a new company. The update mutation can do bulk update on nodes by widening the filter parameters.

The returned payload provides the numUids field that is a count of how many nodes were created or updated. The payload also returns the nodes that were filtered for the update. Field selection on these nodes shows the nodes in their post-mutation state (after they were updated).

Because nodes can be updated and linked to pre-existing nodes, it is possible to traverse these pre-existing nodes to find other nodes that were not provided in the update input.

A mutation can set predicate values in similar fashion as it sets edges.

Something to try. Update the newly created person with xid equal to “karl” and set the age to “42”.


Because the UIDs for nodes are generated dynamically by Dgraph, the id fields that expose these UIDs will use different values in each Dgraph backend instance used for this tutorial. That’s why this lesson uses the xid field instead of the id field.

Something to try: The mutation we provided set Alice as the manager of Frank and Karl and set Alice’s manager as Bob, but it did not link Bob, Frank, or Karl to the employer “Acme Corp.” Update Acme Corp’s employees to include Bob, Frank, and Karl.