Graphql query translated to DQL - filtering

Okay, got it working. As some of the documentation points out, there is a non-trivial mental shift going from a relational db mindset (or even vanilla Graphql mindset) to a native graph db mindset. I can see how this will become intuitive with some practice. Anyway, here’s the answer (or at least the one I arrived at by reviewing the documentation examples more carefully, and experimenting with Ratel). I hope it’s useful for other new users getting the hang of this.

type Query {
	queryMyItems(id: String!): [Item] @custom(dql: """  
		query q($id: string) {
  			var(func:uid($id)){
    			MyItems as User.items
  			}    
  		queryMyItems(func:uid(MyItems)){
			title: Item.title
    		id: uid
  		}
	}
  """)
}

The trick is to use query variables [https://dgraph.io/docs/query-language/query-variables/] to first generate the items linked to a given user, and then to return them as the Item type via graphql. Simple idea, really.

1 Like