Dgraph and GraphQL schemas not aligned

What I want to do

We are testing mutation/queries custom resolvers using the Dgraph JavaScript client (dgraph-js).

We would like to use Dgraph JavaScript client from the mutation custom resolvers to execute mutations creating Transactions, and use GraphQL queries from the UI app to access data from Dgraph GraphQL schema directly.

What I did

A Zero node, a Alpha node and a simple NodeJs server with the business logic were deployed as docker compose services on a single Linux host.

I created the below schema doing a POST to the admin/schema endpoint

# Year
type Year {
  id: ID
  # Year
  year: Int! @search @id
  # Start Date
  startDate: DateTime!
  # End Date
  endDate: DateTime!
  # Is Open
  isOpen: Boolean! @search
  # Closed Date
  closedDate: DateTime
}

type Mutation {
    addCustomYear(year: Int!, startDate: DateTime!, endDate: DateTime!, isOpen: Boolean!, closedDate: DateTime): Year! @custom(http:{
        url: "http://custom_app:3000/1.0/years/addYear"
        method: "POST"
        body: "{ year: $year, startDate: $startDate, endDate: $endDate, isOpen: $isOpen, closedDate: $closedDate }"
    })
}
 
type Query{
    getCustomYears(isOpen: Boolean!): [Year] @custom(http:{
        url: "http://custom_app:3000/1.0/years/show.json?isOpen=$isOpen"
        method: "GET"
    })
}

We create “Years” using the below addCustomYear mutation custom resolver:

const dgraphClientStub = newClientStub();
const dgraphClient = newClient(dgraphClientStub);
// Create a new transaction.
const txn = dgraphClient.newTxn();
// Create year.
const p = {
    year: input.year,
    isOpen: input.isOpen,
    startDate: input.startDate,
    endDate: input.endDate,
    closedDate: input.closedDate
};
// Run mutation.
const assigned = await txn.mutate({ setJson: p });

The situation is that “Years” entities are created but are not accessible querying the GraphQL schema, they are only accessible using DQL.

Querying using DQL we can confirm that an ‘uid’ property was added, that is not part of above the GraphQL schema. Also the ‘id’ defined in schema remains null.

It seems so that the GraphQL schema and DQL schema are not aligned.

We read that both schemas should be aligned so data can be accessed using DQL and GraphQL.

How can we avoid DQL mutations to add the ‘uid’ property and use defined ID property in the schema ? The goal is to access the data using GraphQL.

Year data created …

{
  uid: '0x2',
  year: 201521,
  isOpen: true,
  startDate: '2032-01-01',
  endDate: '2032-12-31'
}

Dgraph metadata

dgraph version

PASTE THE RESULTS OF dgraph version HERE.
Dgraph version : v21.03.0
Dgraph codename : rocket
Dgraph SHA-256 : b4e4c77011e2938e9da197395dbce91d0c6ebb83d383b190f5b70201836a773f
Commit SHA-1 : a77bbe8ae
Commit timestamp : 2021-04-07 21:36:38 +0530
Branch : HEAD
Go version : go1.16.2
jemalloc enabled : true

For Dgraph official documentation, visit https://dgraph.io/docs.
For discussions about Dgraph , visit http://discuss.dgraph.io.
For fully-managed Dgraph Cloud , visit Dgraph Cloud - Fully-managed database-as-a-service - Native GraphQL graph database in the cloud.

Licensed variously under the Apache Public License 2.0 and Dgraph Community License.
Copyright 2015-2021 Dgraph Labs, Inc.

Do this:

const p = {
    "dgraph.type": "Year",
    "Year.year": input.year,
    "Year.isOpen": input.isOpen,
    "Year.startDate": input.startDate,
    "Year.endDate": input.endDate,
    "Year.closedDate": input.closedDate
};

See

That worked! Thanks!