Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created January 18, 2022 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuc-arc-f/c9b0b821f0fc71dcf6a84dd17fb34813 to your computer and use it in GitHub Desktop.
Save kuc-arc-f/c9b0b821f0fc71dcf6a84dd17fb34813 to your computer and use it in GitHub Desktop.
Serverless Framework, apollo-server sample
const { ApolloServer, gql } = require('apollo-server-lambda');
// typeDefs
const typeDefs = gql`
type Query {
hello: String
}
`;
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
/*
playground: {
endpoint: "/dev/graphql"
}
*/
});
exports.graphqlHandler = server.createHandler({
cors: {
origin: true,
credentials: true,
},
});
{
"name": "sls_express7",
"version": "1.0.0",
"description": "",
"main": "graphql.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server-lambda": "^3.6.1",
"graphql": "^16.2.0"
},
"devDependencies": {
"serverless-offline": "^8.3.1"
}
}
service: apollo-lambda
# app and org for use with dashboard.serverless.com
frameworkVersion: "2"
plugins:
- serverless-offline
provider:
name: aws
runtime: nodejs14.x
region: ap-northeast-1
stage: dev
lambdaHashingVersion: 20201221
functions:
graphql:
handler: graphql.graphqlHandler
events:
- http:
path: graphql
method: post
cors: true
- http:
path: graphql
method: get
cors: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment