How to add facets - mutate, graphql and dgo

How can I add a Facet - mutate, graphql and dgo?

Guessing from doc I am trying to set a facet via mutation:

Facets can be created by using the | character to separate the predicate and facet key in a JSON object field name. This is the same encoding schema used to show facets in query results. E.g.

{
    "set": [
    	{
      	  "Box.name": "box one",
        	"Box.items": [
            {
            "Item.name": "item one",
             "Box.items|ok": "yes"
            }
          ]
    	}
    ]
}

graphql:

type Box {
  id: ID!
  name: String!
  items: [Item]
}

type Item {
  name: String!
  ok: bool(Box.items|ok)
}

dgo:

// ItemEntity --
type ItemEntity struct {
	Name  string   `json:"Item.name,omitempty"`
	Ok bool  `json:"Item.ok|Box.ok,omitempty"`
	DType []string `json:"dgraph.type,omitempty"`
}

// BoxEntity --
type BoxEntity struct {
	Uid   string       `json:"Box.uid,omitempty"`
	Name  string       `json:"Box.name,omitempty"`
	Items []ItemEntity `json:"Box.items,omitempty"`
	Ok bool      `json:"Box.items|Item.ok,omitempty"`
	DType []string     `json:"dgraph.type,omitempty"`
}
...
	box := BoxEntity{
		Uid:  "_:box",
		Name: name,
		Items: []ItemEntity{{
			Name:  "Item one",
			DType: []string{"Item"},
		}},
		Ok: true,
		DType: []string{"Box"},
	}

As far I can tell, we don’t have a solution for facets in GraphQL layer for now. As it is in its early stages, you should use the simple GraphQL behave. As GraphQL don’t supports Facets natively we need to giva another solution to that in the future stages of the graphql layer.

cc @michaelcompton

Yes that’s right. We don’t have facets yet in GraphQL, for that, you’ll need to be using GraphQL±

With the first release of GraphQL we’ll also be adding to the docs to include more details on what’s supported and what isn’t as well as a roadmap for future features.

Hi @michaelcompton & @MichelDiz

Sounds very nice with the roadmap - I will keep my first iterations with GraphQL± and hope to be able to use graphql with current version schema(combining /alter schema naming convention <Type><predicate> and graphql schema)?

Regarding facets in current version - it looks like I have to use “Content-Type: application/rdf” to add them via /mutate endpoint:

{
  set {
    _:box <Box.name> "Box one" .
    _:box <dgraph.type> "Box" .
    _:item <Item.name> "Item one" .
    _:item <dgraph.type> "Item" .
    
   _:box <items> _:item (ok=true) .
  }
}

This way, I can set both type and facet - this is ok.

I will get back regarding facets and dgo, when I have scratched my head a little more :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.