Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support expand of types #3903

Closed
campoy opened this issue Sep 3, 2019 · 2 comments
Closed

Support expand of types #3903

campoy opened this issue Sep 3, 2019 · 2 comments
Assignees
Labels
area/querylang Issues related to the query language specification and implementation. area/types Issues related to the type system. kind/feature Something completely new we should consider. status/accepted We accept to investigate/work on it.
Milestone

Comments

@campoy
Copy link
Contributor

campoy commented Sep 3, 2019

Since v1.1.0 Dgraph support types and expand(_all_) is defined as the expansion of all the predicates found in all of the types linked to any of the nodes in the query.

So for instance, if we have two types Person and Aged:

type Person {
   first_name: string
   last_name: string
}

type Aged {
   age: int
}

And we have the following dataset:

{
  set {
    _:a <dgraph.type> "Person" .
    _:a <dgraph.type> "Aged" .
    _:a <first_name> "John" .
    _:a <last_name> "Doe" .
    _:a <age> "42" .
     }
}

When we query all values of type Person and use expand(_all_):

{
  q(func: type(Person)) {
    dgraph.type
    expand(_all_)
  }
}

we end up receiving the field age even though it's not part of the type Person because expand(_all_) expands all of the predicates in all of the types linked to any of the values returned.

{
  "data": {
    "q": [
      {
        "dgraph.type": [
          "Person",
          "Aged"
        ],
        "first_name": "John",
        "age": 42,
        "last_name": "Doe"
      }
    ]
  },
  "extensions": {...}
}

This is because our node John Doe is of type Person and Aged, as the result of the query shows.

I propose a way to expand only the fields related to a type by passing the type name as the parameter to expand.

So, we could send this query:

{
  q(func: type(Person)) {
    dgraph.type
    expand(Person)
  }
}

This would return only the fields first_name and last_name. We could also pass multiple types to the expand query: expand(Person, Aged) and that would expand the union of the predicates.

@campoy campoy added kind/feature Something completely new we should consider. area/querylang Issues related to the query language specification and implementation. status/accepted We accept to investigate/work on it. area/types Issues related to the type system. labels Sep 3, 2019
@campoy campoy added this to the Dgraph v1.2 milestone Sep 3, 2019
@poonai poonai self-assigned this Sep 9, 2019
@poonai poonai assigned martinmr and unassigned poonai Sep 12, 2019
@martinmr
Copy link
Contributor

martinmr commented Oct 4, 2019

@campoy How is this different from #3904 It looks like similar functionality but with different syntax.

@martinmr
Copy link
Contributor

Fixed by #3920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/querylang Issues related to the query language specification and implementation. area/types Issues related to the type system. kind/feature Something completely new we should consider. status/accepted We accept to investigate/work on it.
Development

Successfully merging a pull request may close this issue.

3 participants