Mutation failed because Dgraph execution failed because Some variables are used but not defined

For the following schema

interface ValueMetadata  {
	id: ID! 
	createdAt: DateTime! 
	deletedAt: DateTime 
	author: Author! @hasInverse(field:values)
	owner: Organization! @hasInverse(field:values)
}

type StringValue implements ValueMetadata {
  data: String
}

type IntValue implements ValueMetadata {
  data: Int
}

type FloatValue implements ValueMetadata {
  data: Float
}

type DateTimeValue implements ValueMetadata {
  data:DateTime
}

union Value = StringValue | IntValue | FloatValue | DateTimeValue

type Attribute {
  name: String! @id
  values: [Value!]
}

type Element {
  hash: String! @id
  type: String!
  createdAt: DateTime!
  archived: Boolean
  author: Author! @hasInverse(field:elements)
  owner: Organization! @hasInverse(field:elements)
  attributes: [Attribute!]
}

type Organization  {
	id: String! @id
	name: String 
  elements: [Element!]
  values: [ValueMetadata!]
}

type Author  {
	id: String! @id
	cn: String 
	sn: String 
	email: String! 
  elements: [Element!]
  values: [ValueMetadata!]
}

and for one organization and one author object:

mutation AddOrganization($id: String!) {
  addOrganization(input: {id: $id}) {
    organization {
      id
    }
  }
}

mutation AddAuthor($id: String!, $email: String!) {
  addAuthor(input: {id: $id, email: $email}) {
    author {
      id
      email
    }
  }
}

running this mutation

mutation AddElement($hash: String!,$type:String!, $createdAt: DateTime!,$author: String!, $owner: String!) {
  addElement(input: {
    hash:$hash, 
    type:$type, 
    createdAt: $createdAt, 
    author: {id:$author}, 
    owner:{id: $owner},
    attributes: [
      {
        name: "element_name",
        values: [
          {
            stringValueRef:{
              createdAt: $createdAt
              author:{id: $author}
              owner:{id: $owner}
              data: "Prvy element"
            }
          }
        ]
      },
      {
        name: "city",
        values: [
          {
            stringValueRef:{
              createdAt: $createdAt
              author:{id: $author}
              owner:{id: $owner}
              data: "Bratislava"
            }
          }
        ]
      },
      {
        name: "population",
        values: [
          {
            intValueRef:{
              createdAt: $createdAt
              author:{id: $author}
              owner:{id: $owner}
              data: 1100
            }
          }
        ]
      }
    ]
  }) {
    element {
      hash
      type
      createdAt
      author {
        id
      }
      owner {
        id
      }
      attributes {
        name
        values {
          __typename
          ... on StringValue {
            createdAt
            author {
              id
            }
            owner {
              id
            }
            stringValue: data
          }
          ... on IntValue {
            createdAt
            author {
              id
            }
            owner {
              id
            }
            intValue: data
          }
        }
      }
    }
  }
}

ends with error:

"errors": [
    {
      "message": "mutation addElement failed because Dgraph execution failed because Some variables are used but not defined\nDefined:[Attribute11 Attribute16 Attribute4 Element2 __dgraph__0]\nUsed:[Attribute11 Attribute16 Attribute4 Author7 Element2 Organization9 __dgraph__0]\n",
      "locations": [
        {
          "line": 19,
          "column": 3
        }
      ]
    }
  ],

object are created with variables:

{
  "id": "test",
  "email": "test@test.com",
  "hash": "1",
  "type": "Car",
  "createdAt": "2016-11-21T17:04:29.479Z",
  "author": "test",
  "owner": "test"
}

Is the GraphQL mutation on schema malformed or is it bug in GraphQL resolver?

The GraphQL mutation is not malformed. I tried reproducing this on master and it worked perfectly fine. There was a bug with the way GraphQL mutations were rewritten to DQL.

This bug was fixed with Fix(GraphQL): Refactor Mutation Rewriter for Add and Update Mutations by vmrajas · Pull Request #7409 · dgraph-io/dgraph · GitHub and is available in all versions after 20.11.2 .

You are able to see this error on Slash because Slash is using an earlier version. Dgraph version of Slash is updated periodically.

@gja can share when the next version update of Dgraph on Slash is going to take place.

1 Like

Yes, I see this error on SlashQL. Backend version v20.11.0-11-gb36b4862.

How I can upgrade existing instance to new vesion?

Hey @selmeci

I see that the fix is available on a newer version of Dgraph.
We can roll this version out for your backend before we release it across the fleet.
Could you DM us the endpoint for your Slash backend or the user email that you have used to sign up for Slash?

Thanks.

2 Likes