-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update lambda.md #6876
Update lambda.md #6876
Conversation
Currently we are getting an error: Can not post null, when we make a POST request with the body: query Query { hello } We need to change the default path from / to graphql in the serverless.yml in order to get response from the resolver.
@sergiycheck: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
✅ Deploy Preview for apollo-server-docs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 1e73732:
|
Hi @sergiycheck . We're about to release Apollo Server 4, which moves the responsibility for maintaining the Lambda integration away from the Apollo Server core team and into the hands of Lambda experts (with a new integration package), so this doc page is going to be removed soon. Apollo Server 4 also removes path parsing and the default check for |
Hi @glasser, I am proposing to change serverless.yml configuration file to make things work for now. This file is not related with apollo server source code, it's related with lambda handler and serverless framework. |
I understand, but the file is in a docs page that's going to be deleted in a few days, and if it eventually gets re-created the path thing won't be relevant because Apollo Server will have stopped unnecessarily defaulting to scanning the URL path for I suppose we do keep the ASv3 docs around so I guess I will take a moment to see what's going on here. The line you want to change was updated in #5497 which was released in apollo-server v3.0.1. That release last year removed the "look for Is it possible you're using Apollo Server 2 for some reason? |
I am using Apollo Server 3 for learning purposes. It would not be great for me if the serverless.yml was deleted from docs, because I would have to investigate serverless docs and figure out how to configure that file properly. If Apollo Server v4 is backward compatible and seamless to use and update from v3 It will be easy solution for that small issue with path. |
So again — this is reverting a change that we made a year ago, and my understanding is that the change you're suggesting should not be correct since we actually removed the requirement of apollo-server/packages/apollo-server-lambda/src/ApolloServer.ts Lines 46 to 50 in c367260
It's hard for me to prioritize evaluating the correctness of your change when it's to a package that is about to be unsupported and where the kind of issue (Apollo Server caring about the URL path) is also about to be fully solved. Perhaps you are passing a |
Found that app and tested again. package.json {
"name": "aws-node-sls-apollo",
"scripts": {
"prebuild": "rimraf lib",
"build": "tsc -p ./tsconfig.build.json",
"start": "rimraf .build && sls offline --config sls.dev.yml",
"deploy:dev": "sls -c sls.dev.yml deploy",
"deploy:dev:func": "sls -c sls.dev.yml deploy function --function graphql",
"remove:dev": "sls remove -c sls.dev.yml"
},
"devDependencies": {
"serverless-offline": "^9.2.6",
"serverless-plugin-typescript": "^2.1.2",
"typescript": "^4.7.4"
},
"dependencies": {
"apollo-server-lambda": "^3.10.1",
"graphql": "^16.6.0",
"rimraf": "^3.0.2",
"serverless": "^3.22.0"
}
}
graphql.ts import { ApolloServer, gql } from 'apollo-server-lambda';
import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core';
import { DocumentNode, GraphQLResolveInfo } from 'graphql';
import { APIGatewayEvent, Context, Callback } from 'aws-lambda';
const typeDefs = gql`
type Query {
hello: String
}
`;
// Provide resolver functions for your schema fields
const resolvers = {
Query: {
hello: (_parent, _args, _context, _info: GraphQLResolveInfo) => {
return 'Hello world!';
},
},
};
function getServer(typeDefs: DocumentNode, resolvers) {
const isDev = process.env.NODE_ENV === 'dev';
let server: ApolloServer;
if (!server) {
server = new ApolloServer({
typeDefs,
resolvers,
context: ({ event, context, express }) => {
return {
headers: event.headers,
functionName: context.functionName,
event,
context,
expressRequest: express.req,
};
},
csrfPrevention: true,
cache: 'bounded',
introspection: isDev,
plugins: [ApolloServerPluginLandingPageGraphQLPlayground()],
});
}
return server;
}
exports.graphqlHandler = async function (
event: APIGatewayEvent,
context: Context,
callback: Callback
) {
const server = getServer(typeDefs, resolvers);
const handler = server.createHandler();
const result = await handler(event, context, callback);
return result;
}; sls.dev.yml service: aws-node-project
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs16.x
region: eu-central-1
deploymentMethod: direct
environment:
NODE_ENV: dev
plugins:
- serverless-plugin-typescript
- serverless-offline
functions:
graphql:
handler: src/graphql.graphqlHandler
events:
- http:
path: graphql
method: post
cors: true
- http:
path: graphql
method: get
cors: true
custom:
serverless-offline:
httpPort: 3029
serverlessPluginTypescript:
tsConfigFileLocation: './tsconfig.build.json'
I start the project with the command yarn run start I query the server and get response in the playground with the default configuration for serverless I can't get the response and get an Error. default sls.dev.yml with path: / service: aws-node-project
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs16.x
region: eu-central-1
deploymentMethod: direct
environment:
NODE_ENV: dev
plugins:
- serverless-plugin-typescript
- serverless-offline
functions:
graphql:
handler: src/graphql.graphqlHandler
events:
- http:
path: /
method: post
cors: true
- http:
path: /
method: get
cors: true
custom:
serverless-offline:
httpPort: 3029
serverlessPluginTypescript:
tsConfigFileLocation: './tsconfig.build.json'
The response that I get with the config above |
Currently we are getting an error Can not post null, when we make a POST request with the body
We need to change the default path from / to graphql in the serverless.yml in order to get response from the resolver.