Population after a custom graphql resolver, what does it?

After adding a custom graphql resolver method I had missing populated fields therefor my query would return : Cannot return null for non-nullable field Styles.name.

I have manually populated this exact field and I return it from my resolver method, so why such error?
Is there another population method happening after the resolver? There seems to be.

Can you give us your custom GQL resolver code?

I know for sure I do return a full document with populated associations.
It seems that no matter what I return from the resolver it does get re-populated somewhere else down the line…

module.exports = {
  resolver: {
Query: {
  headline: {
    description: 'Return the homepage headlines',
    resolverOf: 'application::headline.headline.find',
    resolver: async (obj, options, ctx) => {
     // custom find services returning deeply populated documents
      return await strapi.services.headline.find(options);
    },
  }
},
  }
};

Yes that service will return some populated information, if you instead use:
return await strapi.services.headline.find(options, []); that should stop the default population. (Population happens at the query level)

There is definitely a population happening after the resolver, if I output from the resolver the following refs:

module.exports = {
  resolver: {
    Query: {
      headline: {
        description: 'Return the homepage headlines',
        resolverOf: 'application::headline.headline.find',
        resolver: async (obj, options, ctx) => {
          return {
            "_id": "5f7b9fdbb274387e0dd2e905",
            "entries": [
              {
                "_id": "5f7dc1352177a600c13b256f",
                "episode": {
                  "_id": "5f7b635f7281764dfe79cb1a",
                },
              }
            ],
          };
        },
      }
    },
  }
};

I still get my graphql episode response polulated.

I’m not sure what’s after the resolver in Strapi…

1 Like

I’m not sure in this case either, let me poke @alexandrebodin to see if he has any info to add.

Hey @alexandrebodin looking for a quick tip over here :upside_down_face:

Hi @Silvere_Letellier currently the auto population is too much and should (will) be removed in graphql queries so the data gets fetched only if the relations is queried.

The relation resolvers ignore the pre populated data in most cases because it might be missing informations (components inside the relation for example) so it fetches the relations even if you might think it is populated.

We will remove the pre population soon so the performance get a nice improvement :slight_smile:

1 Like

I understand the issue with the auto population, my question is @alexandrebodin :
How do I return from the graphql resolver with manually deeply populated fields and avoid overwriting them by the relation resolvers down the line ?

In my case i’m manually populating at 3 levels which is more than what the relation resolver does I believe.

1 Like

The only way to do that is to create a custom query with a custom type :slight_smile:

1 Like

Hi Alexander, do you know since which version pre-population is removed?
Because I am using Strapi v4.22.0 and graphql plugin still populates nested fields when this is not needed.