# Dgraph Undefined Variables Error in GraphQL

**URL:** <https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625>\
**Category:** GraphQL\
**Tags:** status:accepted, kind:bug\
**Created:** [July 9, 2020, 9:09pm UTC](https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625 "2020-07-09T21:09:45Z")\
**Posts on this page:** 9\
**Page:** 1

<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:** [July 9, 2020, 9:09pm UTC](https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625/1 "2020-07-09T21:09:45Z")

</div>

example schema that should reproduce (If you need full schema let me know)

```auto
type Contact {
  id: ID!
  name: String
  hasTasks: [Task] # tasks that need to be done to this contact
  hasToDos: [Task] # tasks that this contact needs to do
}

type Task {
  id: ID!
  name: String!
  occurrances: [TaskOccurance] @hasInverse(field: task)
  forContact: Contact @hasInverse(field: hasTasks)
  designated: Contact @hasInverse(field: hasToDos)
}

type TaskOccurance { # broken out of Tasks that way a single task can be recurring
  id: ID!
  task: Task @hasInverse(field: occurrances)
  due: DateTime
  comp: DateTime
}

```

Now my query, I want to get contacts and the tasks that need to be done for them, and the tasks that they have to do.

```auto
query {
  queryContact {
    id
    name
    hasTasks {
      id
      name
      occurrances {
        due
        comp
      }
    }
    hasToDos {
      id
      name
      occurrances {
        due
        comp
      }
    }
  }
}

```

which resulted in the following error:

> `Dgraph query failed because Dgraph execution failed because Some variables are used but not defined\nDefined:[]\nUsed:[TaskOccurance1 TaskOccurance2]`

This is all valid schema and should be an acceptable query even without any data present.

Again using version: **v2.0.0-rc1-448-gd5892dc0c**

---

<div class="post-metadata">

**Author:** ![Rahul](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/rahul/32/3645_2.png) [@Rahul](https://discuss.dgraph.io/u/Rahul)\
**Post date:** [July 10, 2020, 1:21pm UTC](https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625/2 "2020-07-10T13:21:28Z")

</div>

> [@amaster507](#):
>
> which resulted in the following error:
> 
> > `Dgraph query failed because Dgraph execution failed because Some variables are used but not defined\nDefined:[]\nUsed:[TaskOccurance1 TaskOccurance2]`
> 
> This is all valid schema and should be an acceptable query even without any data present.

Hi @amaster507,

I created this schema on an empty dgraph instance and then ran your query. It didn’t fail for me but of course there was no data in results because I hadn’t added any.

If you have added some data post which this is happening, please share the data mutation query as well. I will try to replicate.

---

<div class="post-metadata">

**Author:** ![arijit](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/arijit/32/2116_2.png) [@arijit](https://discuss.dgraph.io/u/arijit)\
**Post date:** [July 13, 2020, 4:36am UTC](https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625/4 "2020-07-13T04:36:22Z")

</div>

> [@amaster507](#):
>
> I do have auth rules in my schema, but the dgraph endpoint is still open so you can peek around at the dataset. Hopefully the screenshots above will help.

I was able to execute the above query without getting error. Can you share the JWT claim that you are passing? The error might be related to it.

---

<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:** [July 16, 2020, 11:39pm UTC](https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625/5 "2020-07-16T23:39:41Z")

</div>

@arijit, I am getting this error on a consistent basis now with multiple different queries. Happens more often with deeply nested queries. Any results back yet on a resolution? Were you able to duplicate it with the JWT I sent you in a PM?

---

<div class="post-metadata">

**Author:** ![arijit](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/arijit/32/2116_2.png) [@arijit](https://discuss.dgraph.io/u/arijit)\
**Post date:** [July 17, 2020, 4:58am UTC](https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625/6 "2020-07-17T04:58:02Z")

</div>

Hi @amaster507, I couldn’t find the JWT in PM. Can you reshare it? I will take a look at this today and get back to you with my findings.

---

<div class="post-metadata">

**Author:** ![arijit](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/arijit/32/2116_2.png) [@arijit](https://discuss.dgraph.io/u/arijit)\
**Post date:** [July 21, 2020, 4:26am UTC](https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625/7 "2020-07-21T04:26:06Z")

</div>

Thanks for sharing the JWT. I was able to reproduce the issue locally. I am working on the fix now.

---

<div class="post-metadata">

**Author:** ![arijit](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/arijit/32/2116_2.png) [@arijit](https://discuss.dgraph.io/u/arijit)\
**Post date:** [August 7, 2020, 8:18am UTC](https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625/8 "2020-08-07T08:18:12Z")

</div>

This issue has been fixed and merged to [master](https://github.com/dgraph-io/dgraph/pull/6053).

---

<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:** [August 19, 2020, 7:46pm UTC](https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625/9 "2020-08-19T19:46:00Z")

</div>

@gja,

Can this get pulled into Slash. I am having this error repeatedly. Or, if this has already been pulled into Slash, can you let me know so that I can raise new similar issue.

This is preventing some of my @auth directive rules from being ran until this gets fixed, so an urgency would be appreciated.

---

<div class="post-metadata">

**Author:** ![arijit](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/arijit/32/2116_2.png) [@arijit](https://discuss.dgraph.io/u/arijit)\
**Post date:** [August 20, 2020, 11:20am UTC](https://discuss.dgraph.io/t/dgraph-undefined-variables-error-in-graphql/7625/10 "2020-08-20T11:20:36Z")

</div>

@amaster507 Just confirmed with the slash team. They will pull the changes by tomorrow.
