Repository: strapi/strapi
File: packages/plugins/graphql/server/src/services/builders/resolvers/association.ts (TypeScript)

Code before:
        });

        await strapi.contentAPI.validate.query(transformedArgs, targetContentType, {
          auth,
        });

        const sanitizedQuery = await strapi.contentAPI.sanitize.query(
          transformedArgs,
          targetContentType,
          {
            auth,
          }
        );
        const transformedQuery = strapi.get('query-params').transform(targetUID, sanitizedQuery);

        const isTargetDraftAndPublishContentType =
          contentTypes.hasDraftAndPublish(targetContentType);

        // Helper to check if a field is from built-in queries (not custom resolvers)
        // Use a memoization cache to avoid rebuilding the schema on every call.
        const isBuiltInQueryField = (fieldName: string) => {
          if (fieldName.endsWith('_connection')) return true;

          if (builtInFieldCache.has(fieldName)) {
            return builtInFieldCache.get(fieldName) as boolean;
          }

          try {
            const graphqlService = strapi.plugin('graphql').service('content-api');
            const schema = graphqlService.buildSchema();
            const queryType = schema.getQueryType();
            const result = queryType?.getFields()?.[fieldName] !== undefined;
            builtInFieldCache.set(fieldName, result ?? false);
            return result;
          } catch {
            builtInFieldCache.set(fieldName, false);
            return false;
          }
        };

        // Only inherit status from built-in queries to avoid conflicts with custom resolvers
        const inheritedStatus =
          context.rootQueryArgs?.status &&
          context.rootQueryArgs?._originField &&
          isBuiltInQueryField(context.rootQueryArgs._originField)
            ? context.rootQueryArgs.status
            : null;

        const statusToApply = args.status || inheritedStatus;

        const defaultFilters =

Review comment (performance):
This suggests that we are still doing the provisioning operation during the first request right?
If true, are we ok with the first request to be slower? Would it benefit from being initialized outside of the actual resolver?

Code after:
          auth,
        });

        const sanitizedQuery = await strapi.contentAPI.sanitize.query(
          transformedArgs,
          targetContentType,
          {
            auth,
          }
        );
        const transformedQuery = strapi.get('query-params').transform(targetUID, sanitizedQuery);

        const isTargetDraftAndPublishContentType =
          contentTypes.hasDraftAndPublish(targetContentType);

        // Helper to check if a field is from built-in queries (not custom resolvers)
        // Use the precomputed lookup populated by the content-api service at schema build time.
        const isBuiltInQueryField = (fieldName: string) => {
          const graphqlService = strapi.plugin('graphql').service('content-api');
          return graphqlService.isBuiltInQueryField(fieldName);
        };

        // Only inherit status from built-in queries to avoid conflicts with custom resolvers
        const inheritedStatus =
          context.rootQueryArgs?.status &&
          context.rootQueryArgs?._originField &&
          isBuiltInQueryField(context.rootQueryArgs._originField)
            ? context.rootQueryArgs.status
            : null;

        const statusToApply = args.status || inheritedStatus;

        const defaultFilters =
          isTargetDraftAndPublishContentType && statusToApply
            ? {
                where: {
                  publishedAt: statusToApply === 'published' ? { $notNull: true } : { $null: true },
                },
              }
            : {};

        const dbQuery = merge(defaultFilters, transformedQuery);

        // Sign media URLs if upload plugin is available and using private provider
        const data = await (async () => {
          const rawData = await strapi.db
            .query(contentTypeUID)
            .load(parent, attributeName, dbQuery);
          if (isMediaAttribute && strapi.plugin('upload')) {
            const { signFileUrls } = strapi.plugin('upload').service('file');