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

Improve exports of postPlanResolver-related code #2353

Open
benjie opened this issue Feb 4, 2025 · 0 comments
Open

Improve exports of postPlanResolver-related code #2353

benjie opened this issue Feb 4, 2025 · 0 comments

Comments

@benjie
Copy link
Member

benjie commented Feb 4, 2025

postgraphile/postgraphile/__tests__/schema/v4/defaultOptions.1.export.mjs contains code like:

function Query_tableSetQuery_plan($parent, args, info) {
  const $select = getSelectPlanFromParentAndArgs12($parent, args, info);
  return connection($select, {
    // nodePlan: ($item) => $item,
    cursorPlan($item) {
      return $item.getParentStep ? $item.getParentStep().cursor() : $item.cursor();
    }
  });
}

// ...

const Query_tableSetQuery_postPlanResolvers = [($connection, $parent, fieldArgs, {
  field
}) => {
  const $orderBy = fieldArgs.getRaw("orderBy");
  const $select = $connection.getSubplan();
  const orderByArg = field.args.find(a => a.name === "orderBy");
  $select.apply(extractEnumExtensionValue(orderByArg.type, "pgSelectApply", $orderBy));
  return $connection;
}];

// ...

export const plans = {
  Query: {

// ...

    tableSetQuery: {
      plan($parent, fieldArgs, info) {
        let $result = Query_tableSetQuery_plan($parent, fieldArgs, info);
        for (const ppr of Query_tableSetQuery_postPlanResolvers) {
          $result = ppr($result, $parent, fieldArgs, info);
        }
        return $result;
      },

// ...

  }
};

Ideally we could inline this, and end up with something more like:

export const plans = {
  Query: {
    tableSetQuery: {
      plan($parent, fieldArgs, info) {
        // Call the base plan, and store the result into `$result`
        const $select = getSelectPlanFromParentAndArgs12($parent, args, info);
        let $result = connection($select, {
          // nodePlan: ($item) => $item,
          cursorPlan($item) {
            return $item.getParentStep ? $item.getParentStep().cursor() : $item.cursor();
          }
        });

        // Apply each of the post plan resolvers in an unrolled loop:
        {
          const $orderBy = fieldArgs.getRaw("orderBy");
          const $select = $result.getSubplan();
          const orderByArg = field.args.find(a => a.name === "orderBy");
          $select.apply(extractEnumExtensionValue(orderByArg.type, "pgSelectApply", $orderBy));
          // $result = ... (only if changed)
        }

        return $result;
      },
@github-project-automation github-project-automation bot moved this to 🌳 Triage in V5.0.0 Feb 4, 2025
@benjie benjie removed this from V5.0.0 Feb 4, 2025
@benjie benjie added this to V5.X Feb 4, 2025
@github-project-automation github-project-automation bot moved this to 🌳 Triage in V5.X Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🌳 Triage
Development

No branches or pull requests

1 participant