Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created Jan 18, 2022
Embed
What would you like to do?
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