Gathering detailed insights and metrics for @brikl/apollo-server-lambda
Gathering detailed insights and metrics for @brikl/apollo-server-lambda
Gathering detailed insights and metrics for @brikl/apollo-server-lambda
Gathering detailed insights and metrics for @brikl/apollo-server-lambda
🌍 GraphQL server for Express, Connect, Hapi, Koa and more
npm install @brikl/apollo-server-lambda
Typescript
Module System
Min. Node Version
Node Version
NPM Version
61.9
Supply Chain
93.8
Quality
78.3
Maintenance
100
Vulnerability
100
License
TypeScript (98.51%)
JavaScript (1.33%)
Shell (0.16%)
Total Downloads
2,612
Last Day
1
Last Week
8
Last Month
15
Last Year
136
MIT License
2,986 Commits
1 Watchers
94 Branches
Updated on Apr 21, 2019
Latest Version
0.0.3
Package Id
@brikl/apollo-server-lambda@0.0.3
Unpacked Size
47.60 kB
Size
11.15 kB
File Count
22
NPM Version
6.4.1
Node Version
8.15.1
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
166.7%
8
Compared to previous week
Last Month
-34.8%
15
Compared to previous month
Last Year
-24%
136
Compared to previous year
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'); 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();
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: nodejs8.10 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
To read information about the current request from the API Gateway event (HTTP headers, HTTP method, body, path, ...) or the current Lambda Context (Function Name, Function Version, awsRequestId, time remaining, ...) use the options function. This way they can be passed to your schema resolvers using the context 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 context: ({ event, context }) => ({ 21 headers: event.headers, 22 functionName: context.functionName, 23 event, 24 context, 25 }), 26}); 27 28exports.handler = 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 cors: { 24 origin: '*', 25 credentials: true, 26 }, 27});
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 cors: { 24 origin: true, 25 credentials: true, 26 }, 27});
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
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
204 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