Dgraph GraphQL Tour

Schema

Adding Data - mutating data

Now that you have updated the schema in the previous step, you can use the new mutations created by the GraphQL API to add data. Making changes to the graph stored in a GraphQL dataset is called mutating the data.

If you had a large amount of data to load after updating a GraphQL schema, it might be better to use the Live Loader and add the data as RDF triples. To see an example of GraphQL data mapped to RDF triples, see Intro - Load Data in the previous lesson.

You may notice if you go much further that you have no defined way to uniquely identify a company. The best you can do with your current schema is to query for companies and filter based on their industry, as follows:

{
  queryCompany(filter: { industry: { anyofterms: "Machinery Tech" } }) {
    name
    industry
    managers: employees(filter: { has: manages }) {
      id
      name
      employees: manages {
        id
        name
      }
    }
  }
}

Because the schema doesn’t define a unique identifier for the Company type, Dgraph doesn’t generate the getCompany query for you. Also, you might notice that if you try to run the original mutation again to add companies, then duplicate companies are created, but not duplicate people. This is because people have xid as a unique identifier, but companies don’t have a unique identifier in this schema.

Also, without having a unique identifier for each Company, you can’t update a Person and set their employer to reference a pre-existing Company.

3.2 Adding Data - mutating data