Defer field selection to subquery when using custom DQL

In the custom DQL example, the DQL query explicitly defines the fields to return for each tweet.

However, we may wish to use this custom logic in multiple contexts which require a different set of fields. Since the GraphQL query will define the fields required, there should be a way for the DQL query to defer field selection to the GraphQL query.

1 Like

Hey @smkhalsa

That’s an interesting one.

This should still be possible as in your GraphQL query you can only ask for fields that you want. Then even though everything would be requested in the DQL query, you’d only get the fields you desire.

We can look into supporting something like this. This would require merging the GraphQL and DQL query. Adding this to our list of things to things to look at.

I thought about this, but it’d require manually defining all possible DQL fields which would be brittle (in case you add or remove possible fields). Also, I assume the DQL query with all the fields would be inefficient since all edges would need to be traversed.

The defer functionality I mentioned above is one of the reasons the neo4j-graphql-js cypher directive is so powerful.

That’s a good point.

How do you envision something like that to work with what we have? Can you give some examples of the kind of queries you’d like to do and which parts would you like to defer to GraphQL±?

Using the example from the GraphQL docs, I’m envisioning something like this?

  queryTweetsSortedByAuthorFollowers(search: String!): [Tweets] @custom(dql: """
    query q($search: string) {
        var(func: type(Tweets)) @filter(anyoftext(Tweets.text, $search)) {
                followers as User.followers
            authorFollowerCount as sum(val(followers))
        queryTweetsSortedByAuthorFollowers(func: uid(authorFollowerCount), orderdesc: val(authorFollowerCount)) {

The _defer_ field would simply defer to the GraphQL query.

@pawan any update on this?

Hey @smkhalsa

I’ll be looking into the improvements that we can make for DQL support in GraphQL and will be creating an RFC about it next week. I’ll also add this in there and have a plan of action for this soon.

1 Like

@pawan any update on this?

This and Firebase Auth support (which I understand is coming in the 20-11-0 release) are the main two factors preventing me from migrating to Dgraph

Unfortunately, this won’t make it to 20.11. Other features were prioritized over improvements to Custom DQL. We will look into this again while planning for the next quarter.