Dgraph GraphQL Tour

Schema

Node Identifiers

In the last lesson, we mentioned that the Company type doesn’t have a unique identifier, so you can’t run a pre-built getCompany query or reference a specific company uniquely to create edges to pre-existing nodes.

While this statement was true from the GraphQL API perspective, every node does have a unique identifier (UID) using the ID scalar, even if that identifier is not mapped to a field within the GraphQL schema. UIDs prevent any two nodes from having the same UID, even if they are of different types.

Another change we are making to the schema here is adding a hash based search directive to the Company’s name, and expanding the search directive on the Company’s industry to be both hash-based and term-based.

After pushing this change, any companies queried will then have the id field available for selection which will already be populated with the appropriate node UID.

Something to try: After pushing this schema update, go back to the previous lesson using the Back button to find a query runner, and then try to query the Company type to see ids.

For a bigger challenge: Go back to the previous lesson for a query runner, and then try to mutate Alice (xid: “alice”) and update the Person to link to an existing Company as her employer.

3.3 Node Identifiers