apollo-server: Apollo 2 serverless giving 403
I followed this tutorial https://www.apollographql.com/docs/apollo-server/deployment/lambda.html and when i hit api endpoint, i get following error
“error”: “Response not successful: Received status code 403”
Here is my code graphql.js
`const { ApolloServer, gql } = require(‘apollo-server-lambda’);
// Construct a schema, using GraphQL schema language
const typeDefs = gql type Query { hello: String }
;
// Provide resolver functions for your schema fields const resolvers = { Query: { hello: () => ‘Hello world!’, }, };
const server = new ApolloServer({ typeDefs, resolvers, context: ({ event, context }) => ({ headers: event.headers, functionName: context.functionName, event, context, }), introspection: true, playground: true, });
exports.graphqlHandler = server.createHandler({ cors: { origin: ‘*’, credentials: true, }, });`
My function definition looks like following
functions: graphql: handler: src/graphql.graphqlHandler environment: SLS_DEBUG: true events: - http: path: graphql method: post cors: true integration: lambda-proxy graphiql: handler: src/graphql.graphqlHandler events: - http: path: graphiql method: get integration: lambda-proxy
When i hit my API endpoint https://hu0pzhs59i.execute-api.us-east-1.amazonaws.com/dev/graphiql gives error
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15
@jatinvmehta Ok, I think I figured out the issue. The code in this repo is deployed to:
The problem you were running into is that by default, the GraphQL playground app served by your lambda was attempting to hit
/graphiql
as the API endpoint. It really needed to be hitting/dev/graphql
. For this reason, it makes sense we saw the 403s because the playground was attempting to make requests against a bad endpoint (/graphiql
is not an endpoint,/dev/graphiql
is though).tl;dr this looks to be a bug/feature of GraphQL Playground. Anyway, hopefully your service works as currently deployed and its just a matter of updating the URL in the UI. Let me know if that doesn’t work.
Thanks @kyledetella . I was searching for hours to solve this problem. Imho this should be mentioned in the Deploying with AWS Lambda tutorial.
@jatinvmehta In the Apollo Server constructor you can pass some playground options, including the
endpoint
, but you need to work out the URL you will be deploying to ahead of time.Thanks @kyledetella, this tripped me up too. IMO
apollo-server-lambda
should automagically fix this, or as @illing2005 mentioned the tutorial should mention this point.