Skip to content
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

Issue getting working apollo-lambda-server with example quickstart code #1227

Closed
liamdanielduffy opened this issue Jun 22, 2018 · 7 comments
Closed

Comments

@liamdanielduffy
Copy link

liamdanielduffy commented Jun 22, 2018

https://www.apollographql.com/docs/apollo-server/servers/lambda.html

I think I'm having the same problem as issues #759 and #333, but those issues were closed without much resolution to the root cause.

My current lambda handler (using Netlify's netlify-lambda package to build and deploy) exports a handler called 'handler' (as per the Netlify function requirements):

var server = require('apollo-server-lambda'),
  schema = require('./api/schema');

exports.handler = function(event, context, callback) {
  const handler = server.graphqlLambda({ schema: schema });
  return handler(event, context, (error, output) => {
    console.log(error, output)
    return callback(error, output)
  })
}

This logs:

null { statusCode: null, headers: {}, body: null }
Response with status 0 in 71 ms.
Error during invocation:  RangeError: Invalid status code: null

...when I try to retrieve the schema with a graphiql client.

It seems that the output object has both a null statusCode and null body.

Any idea why the error would be null, but the output would have a null statusCode and body?

My schema file is as follows:

// import resolvers from './resolvers'
// import types from './types'
const { makeExecutableSchema } = require('graphql-tools');

const books = [
  {
    title: "Harry Potter and the Sorcerer's stone",
    author: 'J.K. Rowling',
  },
  {
    title: 'Jurassic Park',
    author: 'Michael Crichton',
  },
];

// The GraphQL schema in string form
const typeDefs = `
  type Query { books: [Book] }
  type Book { title: String, author: String }
`;

// The resolvers
const resolvers = {
  Query: { books: () => books },
};

// Put together a schema
const schema = makeExecutableSchema({
  typeDefs,
  resolvers,
});

export default schema
@evans
Copy link
Contributor

evans commented Jun 23, 2018

@liamdanielduffy Can you try upgrading to the new 2.0 RC and see if there are still issues?

@liamdanielduffy
Copy link
Author

@evans this works great! thank you. do you expect any breaking changes to this new interface for apollo-server-lambda before the final release of 2.0?

@evans
Copy link
Contributor

evans commented Jul 2, 2018

@liamdanielduffy I don't foresee any breaking changes to the lambda integration before the release. Unless @adnsio, @olistic, or you would like to see more features added?

#1279 is following a very similar pattern, so I think we're continuing down the same path.

@olistic
Copy link
Contributor

olistic commented Jul 3, 2018

@evans Nope, I'm good with it but thanks for asking. Looking at #1279, though, I see the author posted this:

This is similar in concept to how the apollo-server-lambda integration works, but it's using ApolloServer.createHandler() instead. I prefer the more specific ApolloServer.graphqlHandler() naming, but I'm happy to change this is you'd prefer to see these lined up.

IMO, those names should be standardized among the integrations, and that could end up being a breaking change (depending on if you agree with that and on what final name you opt for).

@alessiodionisi
Copy link
Contributor

@olistic @evans We should choose a standard and make them all equal, I prefer createHandler() but I'm open to changes 😄

@liamdanielduffy
Copy link
Author

I also like createHandler(), since like @evans mentioned on #1279, apollo-server is built to handle GraphQL-formatted requests, and nothing else (as far as I know). Since there's no other kind of handler to create for an apollo-server, the graphql qualifier in graphqlHandler() seems redundant.

@evans
Copy link
Contributor

evans commented Jul 5, 2018

Awesome, we're going with createHandler in micro as well. Thank you all for weighing in! I'm going to close this now, since the original issue is solved with the RC and we're starting to get off topic(my fault 😳)

@evans evans closed this as completed Jul 5, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants