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

Updated middleware execution to provide new functionality #91

Merged
merged 7 commits into from
Jul 25, 2023

Conversation

BlenderDude
Copy link
Member

@BlenderDude BlenderDude commented Apr 4, 2023

Short circuit middleware execution

You can now opt to return a Lambda result object directly from the middleware. This will cancel the middleware chain, bypass GraphQL request processing, and immediately return the Lambda result.

Example

export const handler = startServerAndCreateLambdaHandler(
  server,
  handlers.createAPIGatewayProxyEventV2RequestHandler(),
  {
    context: async () => {
      return {};
    },
    middleware: [
      async (event) => {
        const psk = Buffer.from('SuperSecretPSK');
        const token = Buffer.from(event.headers['X-Auth-Token']);
        if (
          psk.byteLength !== token.byteLength ||
          crypto.timingSafeEqual(psk, token)
        ) {
          return {
            statusCode: '403',
            body: 'Forbidden',
          };
        }
      },
    ],
  },
);

Closes #102

Closes #108

Closes #97

Closes #85

Closes #84

@changeset-bot
Copy link

changeset-bot bot commented Apr 4, 2023

🦋 Changeset detected

Latest commit: 122430d

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

This PR includes changesets to release 1 package
Name Type
@as-integrations/aws-lambda Minor

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 4, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 122430d:

Sandbox Source
apollo-server-integration-aws-lambda Configuration

Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should get a README update as well, but I don't see anything major!

src/__tests__/middleware.test.ts Outdated Show resolved Hide resolved
src/__tests__/middleware.test.ts Outdated Show resolved Hide resolved
src/lambdaHandler.ts Outdated Show resolved Hide resolved
src/lambdaHandler.ts Outdated Show resolved Hide resolved
@BlenderDude BlenderDude changed the base branch from main to version-3 July 25, 2023 02:15
@BlenderDude BlenderDude force-pushed the da/middleware-execution-updates branch from 74d4e61 to ca3bbfc Compare July 25, 2023 02:19
Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V3! 🚂

@BlenderDude BlenderDude merged commit 71c94df into version-3 Jul 25, 2023
7 checks passed
@BlenderDude BlenderDude deleted the da/middleware-execution-updates branch July 25, 2023 15:14
@github-actions github-actions bot mentioned this pull request Jul 25, 2023
BlenderDude added a commit that referenced this pull request Jul 25, 2023
* Drop support for Node v14, start testing against Node v20 (#110)

* Drop support for Node v14, start testing against Node v20

* Build release PRs on version-* branches

* latest node@16 types

* Updated middleware execution to provide new functionality (#91)

* Updated middleware execution to provide new functionality

* Add missing headers to the changeset

* Remove context modification from result middleware

* Update from review

* Added new README sections and changelog message

* Spelling

* Prettier

* Version Packages (#114)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: Trevor Scheer <trevor.scheer@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants