# Discrepancy when using @id instead of ID

**URL:** https://discuss.dgraph.io/t/discrepancy-when-using-id-instead-of-id/11711
**Category:** GraphQL
**Tags:** dgraph
**Created:** [December 2, 2020, 2:11pm UTC](https://discuss.dgraph.io/t/discrepancy-when-using-id-instead-of-id/11711 "2020-12-02T14:11:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tvvignesh](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/tvvignesh/32/4140_2.png) [@tvvignesh](https://discuss.dgraph.io/u/tvvignesh)
#### Post date: [December 2, 2020, 2:11pm UTC](https://discuss.dgraph.io/t/discrepancy-when-using-id-instead-of-id/11711/1 "2020-12-02T14:11:52Z")

</div>

Hi. Recently, I moved away from using `ID` which gives me auto-generated IDs from Dgraph to `@id` which gives me control of the IDs I generate and this works well except for some problems:

When I was using `ID` before and was doing mutations, ref nodes were automatically created if I do not specify the IDs. For instance, in the below case, the linked node `refInput` will automatically get created with its own ID since I did not specify any here.

```auto
{
	"inputs": [
		{
			"key1": "val1",
			"key2": "val2",
			"refInput": [
				{
					"keyA": "val1",
					"keyB": "val2"
				}
			]
		}
	]
}

```

Now, I am unsure, how to replicate this behavior when using `@id` and specifying my own ID for the node `refInput` without doing 2 separate mutation calls. That is, I was looking to do something like this, and have the refNode automatically created with the ID I specify in a single mutation call:

```auto
{
	"inputs": [
		{
      		"id":"my-generated-id-1",
			"key1": "val1",
			"key2": "val2",
			"refInput": [
				{
          			"id": "my-generated-id-1-for-referred-node",
					"keyA": "val1",
					"keyB": "val2"
				}
			]
		}
	]
}

```

When I try this, I get the error that the referred node does not exist.

I was also facing another issue when using `@id` where recreating nodes with same ID did not return any output which I have filed here: [Returning data when doing a mutation trying to re-create record which was already created - #3 by aman-bansal](http://discuss.hypermode.com/t/returning-data-when-doing-a-mutation-trying-to-re-create-record-which-was-already-created/11707/3)

Not sure what other challenges I may face with `@id`. Yet to see. Any way to fix these? Thanks.

---

<div class="post-metadata">

### Author: ![aman-bansal](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/aman-bansal/32/4475_2.png) [@aman-bansal](https://discuss.dgraph.io/u/aman-bansal)
#### Post date: [December 3, 2020, 11:52am UTC](https://discuss.dgraph.io/t/discrepancy-when-using-id-instead-of-id/11711/2 "2020-12-03T11:52:17Z")

</div>

Hi @tvvignesh, If you notice Ref object doesn’t have data types check like non null constraint. This is by design. If you need the refInput to be created, then please provide all the necessary fields that are required to create the object. The idea is this, if reference object presents then don’t create it else with the other information provided, try to create the child nodes.

For Example, say for schema

```auto
type Book {
  bookId: String! @id
  name: String!
  desc: String
  chapter: Chapter
}

type Chapter {
  chapterId: String! @id
  name: String!
  bookId: String! @search
}

```

If I use the mutation mentioned below, it will result in error that the reference node doesn’t exist, and chapter node is malformed. Second error means we are trying to create the object and it fails.

```auto
mutation{
  addBook(input:[{
    bookId: "bookId"
    name: "name"
    chapter:{
      chapterId: "chapter1"
    }
  }]) {
    
    book{
      bookId
      name
      chapter {
        chapterId
        name
        bookId
      }
    }
  }
}

```

But this mutation works

```auto
mutation{
  addBook(input:[{
    bookId: "bookId"
    name: "name"
    chapter:{
      chapterId: "chapter1"
      name: "chapter name"
      bookId: "bookId"
    }
  }]) {
    
    book{
      bookId
      name
      chapter {
        chapterId
        name
        bookId
      }
    }
  }
}

```

> [@tvvignesh](#):
>
> Not sure what other challenges I may face with `@id`. Yet to see. Any way to fix these? Thanks.

Ideally you shouldn’t. We try to manage the symmetry between `ID` and `@id`. Though has different use cases for users, graphql layer of Dgraph make sure that we treat this in the same way.

---

<div class="post-metadata">

### Author: ![tvvignesh](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/tvvignesh/32/4140_2.png) [@tvvignesh](https://discuss.dgraph.io/u/tvvignesh)
#### Post date: [December 4, 2020, 1:14am UTC](https://discuss.dgraph.io/t/discrepancy-when-using-id-instead-of-id/11711/3 "2020-12-04T01:14:03Z")

</div>

> [@aman-bansal](#):
>
> But this mutation works

Thanks @aman-bansal for your elaborate reply. If I remember right, I did specify all the required fields for the ref node as you mentioned in the second case but still it threw that the ref node does not exist. Will try again and revert back, I may be wrong.
