# Schema review: new to DGraphj

**URL:** <https://discuss.dgraph.io/t/schema-review-new-to-dgraphj/19126>\
**Category:** App Development\
**Tags:** schema\
**Created:** [December 18, 2023, 4:25pm UTC](https://discuss.dgraph.io/t/schema-review-new-to-dgraphj/19126 "2023-12-18T16:25:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rohan\_Surana](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/rohan_surana/32/11530_2.png) [@Rohan\_Surana](https://discuss.dgraph.io/u/Rohan_Surana)\
**Post date:** [December 18, 2023, 4:25pm UTC](https://discuss.dgraph.io/t/schema-review-new-to-dgraphj/19126/1 "2023-12-18T16:25:53Z")

</div>

Hello All!  
I am first time using DGraph. I would love if anyone could review my schema.  
It’s a very basic use case where I have two types of nodes: Tag and Resource. I want to keep the edges unidirectional, as I would query from both sides.  
Additionally, I would often do an exact match on the ‘parentId’ field and ‘anyofterms’ on the key field.

```auto
var Schema = `
type Tag {
  resourceIds: [Resource] 
  organizationId: String
  parentId: String!
  key: String!
  value: String!
}

type Resource {
  name: String!
  tagIds: [Tag] 
}

name: String .
key: String @index(term) .
value: String .
resourceIds: [uid] @count @reverse .
tagIds: [uid] @count @reverse .
organizationId: String @index(hash) .
parentId: String @index(hash) .

`

```

---

<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:** [December 22, 2023, 7:10am UTC](https://discuss.dgraph.io/t/schema-review-new-to-dgraphj/19126/2 "2023-12-22T07:10:34Z")

</div>

You are mixing the DQL and GraphQL syntaxes here. This is not a valid schema. What are you placing to use primarily DQL or GraphQL to mutate and query your data?

---

<div class="post-metadata">

**Author:** ![Rohan\_Surana](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/rohan_surana/32/11530_2.png) [@Rohan\_Surana](https://discuss.dgraph.io/u/Rohan_Surana)\
**Post date:** [December 22, 2023, 7:26am UTC](https://discuss.dgraph.io/t/schema-review-new-to-dgraphj/19126/3 "2023-12-22T07:26:39Z")

</div>

Hi,  
Thank you for your reply. I’ve started some implementation using DQL. I’ve been loading this schema so far and DGraph hasn’t complained about it yet.  
I’m flexible with my backend implementation. I can go with either. Does DQL have performance benefits? If yes, what changes can be made it to make more efficient.

Thank you again!

---

<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:** [December 22, 2023, 8:22pm UTC](https://discuss.dgraph.io/t/schema-review-new-to-dgraphj/19126/4 "2023-12-22T20:22:09Z")

</div>

> **[GraphQL vs DQL - Dgraph Blog](https://dgraph.io/blog/post/graphql-vs-dql/)**
>
> Dgraph is native GraphQL, and has a robust Dgraph Query Language (DQL). But how do the two fit together, and when should you use one or the other?

^ so I don’t have to keep repeating the same explanations

---

<div class="post-metadata">

**Author:** ![Rohan\_Surana](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/rohan_surana/32/11530_2.png) [@Rohan\_Surana](https://discuss.dgraph.io/u/Rohan_Surana)\
**Post date:** [December 23, 2023, 8:31am UTC](https://discuss.dgraph.io/t/schema-review-new-to-dgraphj/19126/5 "2023-12-23T08:31:02Z")

</div>

Thank you for the above blog. It was really helpful.  
Updated my schema, what do you think about it now (made it DQL)

```auto
var Schema = `
type Tag {
  resourceIds [Resource] 
  organizationId string
  parentId string
  key string
  value string
}

type Resource {
  name string
  tagIds [Tag] 
}

name: string .
key: string @index(term) .
value: string .
resourceIds: [uid] @count @reverse .
tagIds: [uid] @count @reverse .
organizationId: string @index(hash) .
parentId: string @index(hash) .

`

```

Thank you again for your time and help.

---

<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:** [December 23, 2023, 5:11pm UTC](https://discuss.dgraph.io/t/schema-review-new-to-dgraphj/19126/6 "2023-12-23T17:11:24Z")

</div>

A few questions…

What is your use case for parentId? Is this going to be used to look up something else? If so, it should be an edge not a predicate.

Are you going to want to keep `resouceIds` and `tagIds` in sync yourself manually? It might be easier to use just the reverse edge for whichever side seems more natural. I would keep the actual edge on the side where you write to most usually. (The primary type)

---

<div class="post-metadata">

**Author:** ![Rohan\_Surana](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/rohan_surana/32/11530_2.png) [@Rohan\_Surana](https://discuss.dgraph.io/u/Rohan_Surana)\
**Post date:** [December 27, 2023, 8:14pm UTC](https://discuss.dgraph.io/t/schema-review-new-to-dgraphj/19126/7 "2023-12-27T20:14:50Z")

</div>

Thank you for your response. ParentId will be mainly used for lookups. You can think of it as n tags associated with one parent ID. How can I make it an edge?

In my implementation currently, I was syncing them manually. Is there a better way to do that? I would mostly write to `resourceIds` and update `tagIds` later. Can you help me with `I would keep the actual edge on the side where you write to most usually. (The primary type)` part?

Thank you so much again!

---

<div class="post-metadata">

**Author:** ![Rohan\_Surana](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/rohan_surana/32/11530_2.png) [@Rohan\_Surana](https://discuss.dgraph.io/u/Rohan_Surana)\
**Post date:** [January 8, 2024, 8:28pm UTC](https://discuss.dgraph.io/t/schema-review-new-to-dgraphj/19126/8 "2024-01-08T20:28:50Z")

</div>

Hi @amaster507  
Based on our previous discussion, I have updated the schema:

```auto
var Schema = `
type Tag {
  organizationId: string
  parentId: Tenant
  key: string
  value: string
  resourceIds: [Resource] 
}

type Resource {
  name: string
  parentId: Tenant
  type: string
  tagIds: [Tag]
  owner: User
  creator: User 
}

type User {
  name: string
  parentId: Tenant
}

# establish a hierarchical relationship
type Tenant { 
  name: string
}

name: string @index(hash) .
key: string @index(term) .
value: string .
resourceIds: [uid] @count @reverse .
owner: uid @reverse .
creator: uid @reverse .
tagIds: [uid] @count @reverse .
organizationId: string @index(hash) .
parentId: uid .
type: string @index(term) .

`

```

What do you think about this schema? Do you have any suggestions on how I can optimize this further?
