graphile / graphile/crystal

Improve exports of postPlanResolver-related code

Open
#2,353 0 comments 0 reactions 0 assignees View on GitHub
✨ feature
Dominant language
TypeScript
Stars
12.9k
Forks
625
Avg merge
5h 23m
Merged PRs (30d)
24

Description

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

```js
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:

```js
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;
},
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.