Expand not work for me

expand cannot return all predicate for me as below. And it should return all predicate like user_name and register_time not only ‘user_id’ predicate as below.

schame as below:

type Chapter {
    chapter_id: Int!
    chapter_title: String! @search(by: [term, fulltext])
    belong_course: Course

type Course {
    course_id: Int!
    course_name: String! @search(by: [term, fulltext])
type Browser{
    browser_times: Int!
    browser_chapter: [Chapter]
type User {
    user_id: Int!
    user_name: String @search(by: [hash])
    register_time: DateTime
    browser: [Browser]

data was imported by dgraph live -f data1.json as below:

[[email protected] ~]# head -2 data1.json
{"user_id":3,"user_name":"ZmoscJ","register_time":"2020-06-08 20:24:03","browser":[{"browser_times":6,"browser_chapter":{"chapter_id":5,"chapter_title":"在你心里,...?","belong_course":{"course_id":5,"course_name":"金融...50讲"}}},{"browser_times":6,"browser_chapter":{"chapter_id":17,"chapter_title":"社交....吗?","belong_course":{"course_id":17,"course_name":"y...讲堂"}}},{"browser_times":2,"browser_chapter":{"chapter_id":8,"chapter_title":"“幸福”","belong_course":{"course_id":8,"course_name":"测试"}}}]}
{"user_id":4,"user_name":"🍃☁⚡💦☔","register_time":"2020-06-08 20:25:06","browser":[{"browser_times":1,"browser_chapter":{"chapter_id":2,"chapter_title":"测试财...","belong_course":{"course_id":2,"course_name":"给...课"}}},{"browser_times":1,"browser_chapter":{"chapter_id":18,"chapter_title":"测试...课","belong_course":{"course_id":18,"course_name":" J...四讲"}}},{"browser_times":2,"browser_chapter":{"chapter_id":1,"chapter_title":"测试...","belong_course":{"course_id":1,"course_name":"给...课"}}},{"browser_times":7,"browser_chapter":{"chapter_id":17,"chapter_title":"社交....吗?","belong_course":{"course_id":17,"course_name":"t讲堂"}}},{"browser_times":1,"browser_chapter":{"chapter_id":16,"chapter_title":"社交...吗?","belong_course":{"course_id":16,"course_name":"基于...设施"}}},{"browser_times":1,"browser_chapter":{"chapter_id":14,"chapter_title":"微信","belong_course":{"course_id":14,"course_name":"经济...的"}}},{"browser_times":1,"browser_chapter":{"chapter_id":6,"chapter_title":"“报....吗","belong_course":{"course_id":6,"course_name":"“报...行”"}}},{"browser_times":8,"browser_chapter":{"chapter_id":5,"chapter_title":"在你...吗?","belong_course":{"course_id":5,"course_name":"金融...50讲"}}},{"browser_times":1,"browser_chapter":{"chapter_id":4,"chapter_title":"“报复...吗","belong_course":{"course_id":4,"course_name":"“报...行”"}}},{"browser_times":1,"browser_chapter":{"chapter_id":3,"chapter_title":"第...课","belong_course":{"course_id":3,"course_name":"金融...课"}}}]}

I don’t see the “dgraph.type” on your dataset. It is mandatory to make things like “expand all” work.

Also, there is any reason why you are using GraphQL Schema and DQL? Just curious. BTW, GraphQL automatically adds the “dgraph.type”.

Do you mean why not using GraphQL Schema and DQL?
Because there are too many data which should be imported into Dgraph . So I have to use dgraph live or bulk to import data with json or rdf file. And I don’t know if there is a easy way to import mass data by GraphQL or DQL.

I will try to add dgraph.type predicate in json data.

It does not work for me . And I don’t know where is the problem.

The data imported by dgraph live -f data2.json is below:

    "user_id": 183,
    "user_name": "曾..",
    "register_time": "2020-09-07 18:13:49",
    "dgraph.type": "User",
    "browser": [
        "dgraph.type": "Browser",
        "browser_chapter|counts": 1,
        "browser_chapter": {
          "chapter_id": 5,
          "chapter_name": "在...吗?",
          "dgraph.type": "Chapter",
          "course": {
            "course_id": 5,
            "dgraph.type": "Course",
            "course_name": "金...讲"

And another question is that facets cannot be queryed as below:

@wwwjljj One thing I note while testing data is that you are defining your schema via GraphQL but data.json file has data compatible with DQL. The predicate creation for GraphQL and DQL is different, hence the issue.
What is happening is while creating schema via GraphQL, Dgraph is creating predicates like .. But during data loading, new predicated gets created with value . This is the design constraint over GraphQL vs DQL. I modified your schema using the @dgraph directive. This should fix your problem.

type Chapter @dgraph(type: "Chapter") {
    chapter_id: Int! @dgraph(pred:"chapter_id")
    chapter_title: String! @search(by: [term, fulltext]) @dgraph(pred:"chapter_title")
    belong_course: Course @dgraph(pred:"belong_course")

type Course @dgraph(type: "Course"){
    course_id: Int! @dgraph(pred:"course_id")
    course_name: String! @search(by: [term, fulltext]) @dgraph(pred:"course_name")
type Browser @dgraph(type: "Browser"){
    browser_times: Int! @dgraph(pred:"browser_times")
    browser_chapter: [Chapter] @dgraph(pred:"browser_chapter")
type User @dgraph(type: "User") {
    user_id: Int! @dgraph(pred:"user_id")
    user_name: String @search(by: [hash]) @dgraph(pred:"user_name")
    register_time: DateTime @dgraph(pred:"register_time")
    browser: [Browser] @dgraph(pred:"browser")

Please try loading the data by specifying the required dgraph.type field as per your requirement.
I recommend you to go through this doc for more details.


The last issue relies on the differences between DQL and GraphQL. The other ones should be fine with the “dgraph.type” solution.

You can use Aman’s solution on schema, or add a GraphQL prefix on the dataset. GraphQL adds this prefix based on the Type on each predicate it creates. I don’t know why this isn’t documented, as I saw several users confused with this.

So, resuming, your dataset should be like

BTW, I don’t remember if the prefix needs to start with capital letters, you need to test it.

    "User.user_id": 183,
    "User.user_name": "曾..",
    "User.register_time": "2020-09-07 18:13:49",
    "dgraph.type": "User",
    "User.browser": [
        "dgraph.type": "Browser",
        "Browser.browser_chapter|counts": 1,
        "Browser.browser_chapter": {
          "Chapter.chapter_id": 5,
          "Chapter.chapter_name": "在...吗?",
          "dgraph.type": "Chapter",
          "course": {
            "Course.course_id": 5,
            "dgraph.type": "Course",
            "Course.course_name": "金...讲"

And if you gonna query via DQL you have to use the prefixed predicates.

If you know what you doing, fine to use GraphQL before DQL. But if you don’t, some things can happen and you can get confused about it. The two although similar are very different things. You should learn the details before using it.

There’s no way to bulk import data in GraphQL. The Live and Bulk are the recommended ones. But, using bulk for GraphQL data, you have to understand the underneath things. Otherwise at each step you will be blocked for a long time.

If you’re not going to use GraphQL however, you shouldn’t be using GraphQL Schema at all. To make things easy.

1 Like

Thank you! :clap:t2:
Now I know the difference between GraphQL and DQL when importing data.
I will learn the doc for the 2th time to avoid the same mistake.