mickhansen/dataloader-sequelize

Associations that just retrieve belongsTo id should not execute unnecessary query

mschipperheyn opened this issue · 1 comments

I noticed an inefficiency that I think warrants a small optimization:

Let's assume the following type definition

type User {
   id: ID!
   bestFriend: User # based on belongsTo
}

If on the client side I have the following fragment:

fragment userFragment on User {
     id
     bestFriend {
         id
    }
}

I see a separate query being executed for bestFriend. Since the bestFriend id is available on the root, this query should not be executed.

An alternative would be to add bestFriendId on the User type, but I would consider that hackish.

This is not related to dataloader-sequelize.
Whatever resolves bestFriend would need to handle that, dataloader-sequelize is not graphql specific and does not look at request AST.