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

Enhancement: ignore extra keys in withRelated option? #2102

Open
Rio6 opened this issue Feb 5, 2021 · 0 comments
Open

Enhancement: ignore extra keys in withRelated option? #2102

Rio6 opened this issue Feb 5, 2021 · 0 comments

Comments

@Rio6
Copy link

Rio6 commented Feb 5, 2021

Introduction

I'm looking into using https://github.com/Mikhus/graphql-fields-list to look ahead into a GralhQL query so bookshelf can fetch the related data at once. The problem is most of keys it returns are not foreign relations in the model, so directly adding them to withRelated would cause error when fetching. Perhaps there can be an option to tell bookshelf to ignore extra withRelated options when they don't exist?

Issue Description

Since the list can have multiple nested levels, simply filtering at the top level would work. And since the fetching process is already traversing down the relations, I figure it might be more efficient to just ignore the errors rather than do another relation building and traversal beforehand. Let me know if there are better way to do this however.

Changing the line in base/eager.js

throw new Error(relationName + ' is not defined on the model.');

to a continue seem to work. Although I'm not too familiar with the code base to know if it might break other parts.

Potentially, this option can also make it ignore functions that doesn't return relation data.

Expected behaviour

Being able to specify withRelated with extra keys in it.

Actual behaviour

Bookshelf throws an error complaining key not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant