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

makeExtendSchemaPlugin: add ability to define field scope as part of plans #1920

Merged
merged 8 commits into from
Jan 25, 2024

Conversation

benjie
Copy link
Member

@benjie benjie commented Jan 25, 2024

Description

Can now define field scope as part of plans:

const SGrovePlugin = makeExtendSchemaPlugin((build) => {
  const { sql } = build;
  const email = build.input.pgRegistry.pgResources.email;
  return {
    typeDefs: gql`
      extend type Email {
        threadAncestors: EmailsConnection
      }
    `,
    plans: {
      Email: {
        threadAncestors: {
          // 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇
          scope: {
            isPgFieldConnection: true,
            pgFieldResource: email,
          },
          // 👆 👆 👆 👆 👆 👆 👆 👆 👆 👆
          plan($email) {
            const $refs = $email.get("refs");

            const $ancestors = email.find();
            $ancestors.where(
              sql`${
                $ancestors.alias
              }.id in (select unnest(${$ancestors.placeholder($refs)}))`,
            );

            return connection($ancestors);
          },
        },
      },
    },
  };
});

This still averts the need for embed() used in V4.

Further, have made the system automatically guess the scope for connection types, so when using a connection type all the arguments you'd expect (first, last, before, after, offset, condition, orderBy, etc) are automatically added. You can disable this by overwriting the scope as shown above, but setting undefined as the values for the keys.

Fixes graphile/crystal-pre-merge#476

Performance impact

Build-time only.

Security impact

None known.

Checklist

  • My code matches the project's code style and yarn lint:fix passes.
  • I've added tests for the new feature, and yarn test passes.
  • I have detailed the new feature in the relevant documentation.
  • I have added this feature to 'Pending' in the RELEASE_NOTES.md file (if one exists).
  • If this is a breaking change I've explained why.

Copy link

changeset-bot bot commented Jan 25, 2024

🦋 Changeset detected

Latest commit: d9d7d43

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
graphile-utils Patch
postgraphile Patch
pgl Patch
graphile Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@benjie benjie merged commit 07244e8 into main Jan 25, 2024
24 checks passed
@benjie benjie deleted the extend-schema-scope branch January 25, 2024 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Give makeExtendSchemaPlugin a way of associating scopes with the created types
1 participant