Created
January 18, 2022 04:47
-
-
Save kuc-arc-f/c9b0b821f0fc71dcf6a84dd17fb34813 to your computer and use it in GitHub Desktop.
Serverless Framework, apollo-server sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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