Basic expand not working on 1st level

Hey Dgraphers,

I’m a newcomer in the Dgraph community!

I’ve been browsing the doc and watching tutorials and I still can figure why my expand(_all_) does not return results.
I’m aware that a dgraph.type must be assigned for results to be expanded.

Here’s the actual issue:

query {
    q(func: type(Therapist)) {
      firstname
      uid
      dgraph.type
    }
  }
{
  "data": {
    "q": [
      {
        "uid": "0x4e22",
        "firstname": "Max-Antoine",
        "dgraph.type": [
          "Therapist"
        ]
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 225300,
      "processing_ns": 9474800,
      "encoding_ns": 33300,
      "assign_timestamp_ns": 30056100,
      "total_ns": 40505900
    },
    "txn": {
      "start_ts": 51460
    },
    "metrics": {
      "num_uids": {
        "_total": 3,
        "dgraph.type": 1,
        "firstname": 1,
        "uid": 1
      }
    }
  }
}

Same with expand, no result:

query {
    q(func: type(Therapist)) {
	expand(_all_)
    }
  }
{
  "data": {
    "q": []
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 792700,
      "processing_ns": 59772200,
      "encoding_ns": 38600,
      "assign_timestamp_ns": 39873100,
      "total_ns": 104427100
    },
    "txn": {
      "start_ts": 51467
    },
    "metrics": {
      "num_uids": {
        "Therapist.agreements": 1,
        "Therapist.airtable_id": 1,
        "Therapist.certified": 1,
        "Therapist.creation": 1,
        "Therapist.description": 1,
        "Therapist.email": 1,
        "Therapist.expiration": 1,
        "Therapist.firstname": 1,
        "Therapist.languages": 1,
        "Therapist.lastname": 1,
        "Therapist.offices": 1,
        "Therapist.payment_types": 1,
        "Therapist.phone": 1,
        "Therapist.photo": 1,
        "Therapist.price": 1,
        "Therapist.slug": 1,
        "Therapist.socials": 1,
        "Therapist.subscription": 1,
        "Therapist.symptoms": 1,
        "Therapist.therapies": 1,
        "Therapist.timetable": 1,
        "_total": 21,
        "dgraph.type": 0
      }
    }
  }
}

I would expect the various predicates to be displayed (firstname, lastname…) but it’s an empty result.

I see dgraph.type at the very end that says “0” and I suppose it might be related.

Thanks so much for giving a hand to a newcomer, I will very much appreciate a community support :slight_smile:

Welcome @vinyll
In order for expand(_all_) to pick the fields, you need to declare the type in the schema definition. Please create the type Therapist with firstname and you should see results. You can use Ratel to create types.

Thanks for your prompt help @anand!

I may have missed something here because I feel like I did it create the type “Therapist”.

I have a

Type Therapist {
  firstname
  lastname
  …
}

In the schema. I assume that’s why I can filter q(func: type(Therapist)) and I can read "dgraph.type": ["Therapist"]in the reply when using explicit predicates like uid and firstname.
My schema in Ratel also mentions <Therapist.firstname>: string .

Can you see something I missed here?

Hi @vinyll.
Your type should look something like this. Please try it out.

type Therapist {
  Therapist.firstname
  Therapist.lastname
  …
}

Right, the idea was there indeed

type Therapist {
  Therapist.firstname
  Therapist.lastname
  …
}

rose the following error:

{"errors":[{"message":"line 1 column 0: Unexpected token: lex.Item [6] \"{\" at 1:0 while parsing schema","extensions":{"code":"Error"}}]}

However, saving with the following would save in the appropriate subject:

{
  set {
    _:john <graph.type> "Therapist" .
    _:john <therapist.firstname> "John" .
    _:john <therapist.lastname> "Doe" .
  }
}

The error I had done was to create the object with _:john <firstname> "John" . instead and that would first create the firstname schema (yes, it creates a schema on its own…) and it would not assign it to the Therapist type, even though <graph.type> "Therapist" is mentionned.

That is very confusing… :confused:

Anyways, I’m not stuck anymore at least and I can move on my learning now.

Thanks again @anand, that’s very helpful not to feel alone with a new tool like this. :+1:

1 Like

Hi @vinyll,
Happy to help. Please do ping us if you get stuck!