-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Closed
Labels
issue: enhancementIssue suggesting an enhancement to an existing featureIssue suggesting an enhancement to an existing featureseverity: lowIf the issue only affects a very niche base of users and an easily implemented workaround can solveIf the issue only affects a very niche base of users and an easily implemented workaround can solvesource: plugin:graphqlSource is plugin/graphql packageSource is plugin/graphql packagestatus: confirmedConfirmed by a Strapi Team member or multiple community membersConfirmed by a Strapi Team member or multiple community members
Description
Bug report
Describe the bug
When using custom processing in a model controller to filter nested relations, it's bypassed by graphql plugin.
Steps to reproduce the behavior
- Create a model
B - Create a model
Awith a fieldentities(one to many :B) - Edit
api/A/controllers/a.jsand add a customfindOnecontroller (but same behaviour with all controllers) :
module.exports = {
lifecycles: {
async findOne(ctx) {
const data = // query data
data.entities = [];
return data;
}
}
}- query you model via graphql
query MyModelA {
projectState(id:"azertyuiop"){
id
entities {
id
}
}
}Expected behavior
The data returned by graphql plugin should be the one returned by controller:
{
"data": {
"a": {
"id": "azertyuiop",
"entities": []
}
}
}Instead we receive this:
{
"data": {
"a": {
"id": "azertyuiop",
"entities": [
{
"id": "abcdefgh",
},
{
"id": "ijklmnop",
},
]
}
}
}Screenshots
N/A
Code snippets
If applicable, add code samples to help explain your problem.
System
- Node.js version: 10.19.0
- YARN version: 1.22.5
- Strapi version: 3.3.3
- Database: Mongo DB
- Operating system: Ubuntu 20.04
Additional context
After investigating a bit, it seems that graphql plugin queries manually nested relations without using controller for each queried relation:
// strapi-plugin-graphql/services/data-loader.js:159
return strapi.plugins['content-manager'].services['contentmanager'].fetchAll(modelUID, params);This results in a query to ORM model (mongoose, here) instead of controller.
I'm not really familiar with apollo server and the way it's been implemented here but wouldn't it be possible to query nested relations via their controller ?
domstarkey and hgulersen
Metadata
Metadata
Assignees
Labels
issue: enhancementIssue suggesting an enhancement to an existing featureIssue suggesting an enhancement to an existing featureseverity: lowIf the issue only affects a very niche base of users and an easily implemented workaround can solveIf the issue only affects a very niche base of users and an easily implemented workaround can solvesource: plugin:graphqlSource is plugin/graphql packageSource is plugin/graphql packagestatus: confirmedConfirmed by a Strapi Team member or multiple community membersConfirmed by a Strapi Team member or multiple community members