AWS Lambda support
See original GitHub issueI’ve been prototyping an API to use with AWS Lambda and this is a basic example of what it could look like:
import { GraphQLLambda } from 'graphql-yoga';
const typeDefs = `
type Query {
hello(name: String): String!
}
`;
const resolvers = {
Query: {
hello: (_, { name}) => `Hello ${name || 'World'}`,
},
}
const handler = new GraphQLLambda({ typeDefs, resolvers });
export const graphql = handler.graphql;
export const playground = handler.playground;
The implementation would be simple to put together for basic use cases, but subscriptions and file-upload would be missing. Binary file-upload is possible already with AWS lambda through API gateway, but if you’re using serverless framework (which I imagine most people are), it doesn’t currently support it as a configuration option. I’ll likely open an issue with serverless to add binary pass-through as an option. Following that, apollo-upload-server
would also need lambda support, but that is a trivial addition that I can do.
Subscriptions are the one feature that cannot be entirely handled in lambda. What works instead is having a separate subscription server using express graphql-yoga or some other http server with websocket support and then use remoteSchemaStitching to then have the subscription server resolve queries through the lambda interface.
Looking for some feedback on this approach before anything gets implemented. Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:12 (5 by maintainers)
Top GitHub Comments
Lambda support is released in v0.9.0.
Initially, I think in the case of Lambda, it would be great to have support for using a schema string in a local variable, or reading from a local .graphql file. For a Lambda, it is probably better to cache the schema locally, since you get billed for execution time.
Then, later on, you could add support for graphql-config, for the more intensive cases that people may have.