Gathering detailed insights and metrics for @greguintow/apollo-server-lambda
Gathering detailed insights and metrics for @greguintow/apollo-server-lambda
Gathering detailed insights and metrics for @greguintow/apollo-server-lambda
Gathering detailed insights and metrics for @greguintow/apollo-server-lambda
🌍 Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.
npm install @greguintow/apollo-server-lambda
Typescript
Module System
Min. Node Version
Node Version
NPM Version
59.2
Supply Chain
54.3
Quality
71.3
Maintenance
100
Vulnerability
98.9
License
@apollo/server@4.12.0
Updated on Apr 07, 2025
@apollo/server-integration-testsuite@4.12.0
Updated on Apr 07, 2025
@apollo/server@4.11.3
Updated on Jan 03, 2025
@apollo/server-integration-testsuite@4.11.3
Updated on Jan 03, 2025
@apollo/server-plugin-response-cache@4.1.4
Updated on Jan 03, 2025
@apollo/server@4.11.2
Updated on Oct 29, 2024
TypeScript (56.2%)
JavaScript (43.39%)
Shell (0.41%)
Total Downloads
463
Last Day
1
Last Week
7
Last Month
14
Last Year
110
MIT License
13,877 Stars
8,472 Commits
2,030 Forks
203 Watchers
87 Branches
576 Contributors
Updated on May 10, 2025
Minified
Minified + Gzipped
Latest Version
3.4.10
Package Id
@greguintow/apollo-server-lambda@3.4.10
Unpacked Size
104.10 kB
Size
33.65 kB
File Count
19
NPM Version
lerna/4.0.0/node@v14.15.4+x64 (linux)
Node Version
14.15.4
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
75%
7
Compared to previous week
Last Month
-26.3%
14
Compared to previous month
Last Year
14.6%
110
Compared to previous year
5
1
1
This is the AWS Lambda integration of GraphQL Server. Apollo Server is a community-maintained open-source GraphQL server that works with many Node.js HTTP server frameworks. Read the docs. Read the CHANGELOG.
1npm install apollo-server-lambda graphql
To deploy the AWS Lambda function we must create a Cloudformation Template and a S3 bucket to store the artifact (zip of source code) and template. We will use the AWS Command Line Interface.
In a file named graphql.js
, place the following code:
1const { ApolloServer, gql } = require('apollo-server-lambda');
2const { ApolloServerPluginLandingPageGraphQLPlayground } = require('apollo-server-core');
3
4// Construct a schema, using GraphQL schema language
5const typeDefs = gql`
6 type Query {
7 hello: String
8 }
9`;
10
11// Provide resolver functions for your schema fields
12const resolvers = {
13 Query: {
14 hello: () => 'Hello world!',
15 },
16};
17
18const server = new ApolloServer({
19 typeDefs,
20 resolvers,
21
22 // By default, the GraphQL Playground interface and GraphQL introspection
23 // is disabled in "production" (i.e. when `process.env.NODE_ENV` is `production`).
24 //
25 // If you'd like to have GraphQL Playground and introspection enabled in production,
26 // install the Playground plugin and set the `introspection` option explicitly to `true`.
27 introspection: true,
28 plugins: [ApolloServerPluginLandingPageGraphQLPlayground()],
29});
30
31exports.handler = server.createHandler();
The bucket name must be universally unique.
1aws s3 mb s3://<bucket name>
This will look for a file called graphql.js with the export graphqlHandler
. It creates one API endpoints:
/graphql
(GET and POST)In a file called template.yaml
:
1AWSTemplateFormatVersion: '2010-09-09' 2Transform: AWS::Serverless-2016-10-31 3Resources: 4 GraphQL: 5 Type: AWS::Serverless::Function 6 Properties: 7 Handler: graphql.handler 8 Runtime: nodejs14.x 9 Events: 10 AnyRequest: 11 Type: Api 12 Properties: 13 Path: /graphql 14 Method: ANY
This will read and transform the template, created in previous step. Package and upload the artifact to the S3 bucket and generate another template for the deployment.
1aws cloudformation package \ 2 --template-file template.yaml \ 3 --output-template-file serverless-output.yaml \ 4 --s3-bucket <bucket-name>
This will create the Lambda Function and API Gateway for GraphQL. We use the stack-name prod
to mean production but any stack name can be used.
aws cloudformation deploy \
--template-file serverless-output.yaml \
--stack-name prod \
--capabilities CAPABILITY_IAM
apollo-server-lambda
is built on top of apollo-server-express
. It combines the HTTP server framework express
with a package called @vendia/serverless-express
that translates between Lambda events and Express requests. By default, this is entirely behind the scenes, but you can also provide your own express app with the expressAppFromMiddleware
option to createHandler
:
1const { ApolloServer } = require('apollo-server-lambda'); 2const express = require('express'); 3 4exports.handler = server.createHandler({ 5 expressAppFromMiddleware(middleware) { 6 const app = express(); 7 app.use(someOtherMiddleware); 8 app.use(middleware); 9 return app; 10 } 11});
Your ApolloServer's context
function can read information about the current operation from both the original Lambda data structures and the Express request and response created by @vendia/serverless-express
. These are provided to your context
function as event
, context
, and express
options.
The event
object contains the API Gateway event (HTTP headers, HTTP method, body, path, ...). The context
object (not to be confused with the context
function itself!) contains the current Lambda Context (Function Name, Function Version, awsRequestId, time remaining, ...). express
contains req
and res
fields with the Express request and response. The object returned from your context
function is provided to all of your schema resolvers in the third context
argument.
1const { ApolloServer, gql } = require('apollo-server-lambda'); 2 3// Construct a schema, using GraphQL schema language 4const typeDefs = gql` 5 type Query { 6 hello: String 7 } 8`; 9 10// Provide resolver functions for your schema fields 11const resolvers = { 12 Query: { 13 hello: () => 'Hello world!', 14 }, 15}; 16 17const server = new ApolloServer({ 18 typeDefs, 19 resolvers, 20 context: ({ event, context, express }) => ({ 21 headers: event.headers, 22 functionName: context.functionName, 23 event, 24 context, 25 expressRequest: express.req, 26 }), 27}); 28 29exports.graphqlHandler = server.createHandler();
To enable CORS the response HTTP headers need to be modified. To accomplish this use the cors
option.
1const { ApolloServer, gql } = require('apollo-server-lambda'); 2 3// Construct a schema, using GraphQL schema language 4const typeDefs = gql` 5 type Query { 6 hello: String 7 } 8`; 9 10// Provide resolver functions for your schema fields 11const resolvers = { 12 Query: { 13 hello: () => 'Hello world!', 14 }, 15}; 16 17const server = new ApolloServer({ 18 typeDefs, 19 resolvers, 20}); 21 22exports.handler = server.createHandler({ 23 expressGetMiddlewareOptions: { 24 cors: { 25 origin: '*', 26 credentials: true, 27 } 28 }, 29});
To enable CORS response for requests with credentials (cookies, http authentication) the allow origin header must equal the request origin and the allow credential header must be set to true.
1const { ApolloServer, gql } = require('apollo-server-lambda'); 2 3// Construct a schema, using GraphQL schema language 4const typeDefs = gql` 5 type Query { 6 hello: String 7 } 8`; 9 10// Provide resolver functions for your schema fields 11const resolvers = { 12 Query: { 13 hello: () => 'Hello world!', 14 }, 15}; 16 17const server = new ApolloServer({ 18 typeDefs, 19 resolvers, 20}); 21 22exports.handler = server.createHandler({ 23 expressGetMiddlewareOptions: { 24 cors: { 25 origin: true, 26 credentials: true, 27 } 28 }, 29});
The options correspond to the express cors configuration with the following fields(all are optional):
origin
: boolean | string | string[]methods
: string | string[]allowedHeaders
: string | string[]exposedHeaders
: string | string[]credentials
: booleanmaxAge
: numberGraphQL Server is built with the following principles in mind:
Anyone is welcome to contribute to GraphQL Server, just read CONTRIBUTING.md, take a look at the roadmap and make your first PR!
No vulnerabilities found.
Reason
26 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 3/24 approved changesets -- score normalized to 1
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
18 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More