apollo-server-integrations / apollo-server-integration-aws-lambda

An integration to use AWS Lambda as a hosting service with Apollo Server
MIT License
46 stars 9 forks source link

Updated middleware execution to provide new functionality #91

Closed BlenderDude closed 1 year ago

BlenderDude commented 1 year ago

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[bot] commented 1 year ago

🦋 Changeset detected

Latest commit: 122430d54e8563e9563da5f3cf88347c78da3985

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[bot] commented 1 year ago

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 122430d54e8563e9563da5f3cf88347c78da3985:

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