Using GraphQL after setting data through DQL returns no results


Report a GraphQL Bug

What edition and version of Dgraph are you using?

Edition:

  • SlashGraphQL
  • Dgraph (community edition/Dgraph Cloud)

If you are using the community edition or enterprise edition of Dgraph, please list the version:

Dgraph Version
$ dgraph version
 
v21.03.1

Have you tried reproducing the issue with the latest release?

Yes

Steps to reproduce the issue (paste the query/schema if possible)

  • I have a local setup of Dgraph using the standalone version docker image and another container running RatelUI.
  • Added predicates through RatelUI using the set mutation and all data was added successfully. The predicates were typed, so for email for instance, the predicate is User.email.
  • Created a GraphQL Schema to match the predicate structure used in the first step. Schema created successfully along with the queries/mutations.

Expected behaviour and actual result.

Expected Behavior

  • When using queryUser, I should get all users added through GraphQL mutation addUser and users added through DQL in RatelUI.
  • At the same time, I should get all users using DQL
{
   users(func: has()){
       uid
       name: User.email
   }

}

Actual Results

  • Using the GraphQL query, queryUser, I only get users that were added using addUser mutation (expectation not met)
  • Using DQL, I actually get all the results whether added in RatelUI (DQL) or GraphQL (Expectation met reality)

So you have a sample of your DQL set mutation? This should work and there is not enough info here to see the problem or to duplicate.

My bad, here are more details. These are not exactly the emails I have in place, so I have modified them to look anonymous

DQL set mutation:

[
  {
    "User.email": "user1@hotmail.com",
  },
  {
    "User.email": "user2@gmail.com",
  },
  {
    "User.email": "user3@gmail.com",
  }
]

DQL Query and Result

Query

{
	receipts(func: has(User.email)){
  	  uid
 	  email: User.email

	}
}

Result

{
  "data": {
    "receipts": [
     {
        "uid": "0x6b4c",
        "email": "user1@hotmail.com"
      },
      {
        "uid": "0x6b4d",
        "email": "user3@gmail.com"
      },
      {
        "uid": "0x6b50",
        "email": "user2@gmail.com"
      },
    ]
  },
}

Schema (User)

This schema was set using the /admin API

type User {
    id: ID!
    email: String
}

GraphQL Query and its result:

Query


query {
  queryUser {
    id
    email
  }
}

Result

{
  "data": {
    "queryUser": []
  }
}

Please let me know if more info is required :smiley:

You need to add in the dgraph.type predicate

https://dgraph.io/docs/query-language/type-system/#setting-the-type-of-a-node

But your data is not typed…

Should be:

[
  {
    "dgraph.type": "User",
    "User.email": "user1@hotmail.com",
  },
  {
    "dgraph.type": "User",
    "User.email": "user2@gmail.com",
  },
  {
    "dgraph.type": "User",
    "User.email": "user3@gmail.com",
  }
]

You could alternatively run an upsert mutation that adds the dgraph.type for all nodes that have the User.email predicate already.

3 Likes

@amaster507 Thanks very much :smiley: , that did the trick

1 Like