# Dgraph and GraphQL schemas not aligned

**URL:** <https://discuss.dgraph.io/t/dgraph-and-graphql-schemas-not-aligned/14117>\
**Category:** Dgraph\
**Created:** [May 11, 2021, 8:25pm UTC](https://discuss.dgraph.io/t/dgraph-and-graphql-schemas-not-aligned/14117 "2021-05-11T20:25:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anibal\_Aguirre](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anibal_aguirre/32/8002_2.png) [@Anibal\_Aguirre](https://discuss.dgraph.io/u/Anibal_Aguirre)\
**Post date:** [May 11, 2021, 8:25pm UTC](https://discuss.dgraph.io/t/dgraph-and-graphql-schemas-not-aligned/14117/1 "2021-05-11T20:25:42Z")

</div>

## 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

```auto
# 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:

```auto
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 …

```auto
{
  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 [Overview - Dgraph](https://dgraph.io/docs).  
> For discussions about Dgraph , visit [http://discuss.hypermode.com](http://discuss.hypermode.com).  
> For fully-managed Dgraph Cloud , visit [Overview - Dgraph](https://dgraph.io/cloud).
> 
> Licensed variously under the Apache Public License 2.0 and Dgraph Community License.  
> Copyright 2015-2021 Dgraph Labs, Inc.

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [May 11, 2021, 8:37pm UTC](https://discuss.dgraph.io/t/dgraph-and-graphql-schemas-not-aligned/14117/2 "2021-05-11T20:37:20Z")

</div>

Do this:

```auto
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

> [@New to Dgraph? DQL vs. GraphQL, Endpoints, Headers, and Schema Translation](http://discuss.hypermode.com/t/new-to-dgraph-dql-vs-graphql-endpoints-headers-and-schema-translation/10443/1):
>
> I would like to better understand the relationship between the DQL schemas and the GraphQL schemas

---

<div class="post-metadata">

**Author:** ![Anibal\_Aguirre](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anibal_aguirre/32/8002_2.png) [@Anibal\_Aguirre](https://discuss.dgraph.io/u/Anibal_Aguirre)\
**Post date:** [May 12, 2021, 12:46pm UTC](https://discuss.dgraph.io/t/dgraph-and-graphql-schemas-not-aligned/14117/3 "2021-05-12T12:46:53Z")

</div>

That worked! Thanks!
