apollo-server-lambda: ^2.15.0
So I'm having this problem after moving from netlify to aws lambda direct using the serverless framework. My code is below.
`const { ApolloServer } = require("apollo-server-lambda");
const mongoose = require("mongoose");
const Sentry = require("@sentry/node");
const { SENTRY_DSN, MONGODB_CONNECTION_STRING } = require("./config");
mongoose.connect(MONGODB_CONNECTION_STRING, { useNewUrlParser: true });
const { merge } = require("lodash");
const base = require("./base");
const auth = require("./auth");
Sentry.init({ dsn: SENTRY_DSN, environment: process.env.NODE_ENV });
const resolvers = merge(
base.resolvers,
auth.resolvers
)
console.log(resolvers);
const server = new ApolloServer({
typeDefs: [
base.typeDefs,
auth.typeDefs,
picolo.typeDefs,
ringoffire.typeDefs,
],
resolvers,
schemaDirectives: {
auth: auth.directives.AuthDirective,
},
context: ({ event, context }) => {
const token = event.headers.authorization || event.headers.Authorization || '';
return { token, event, context };
},
});
exports.graphqlHandler = server.createHandler({
cors: {
origin: '*',
credentials: true,
},
});
`
But it comes up with this error (and the resolvers are actually logging, so they are all legit.
offline: POST /dev/graphql (位: graphql)
{
Party: { account: [AsyncFunction: account] },
Query: {
parties: [AsyncFunction: parties],
user: [AsyncFunction: user],
users: [AsyncFunction: users],
cards: [AsyncFunction: cards]
},
Mutation: {
upsertParty: [AsyncFunction: upsertParty],
deleteParty: [AsyncFunction: deleteParty],
register: [AsyncFunction: register],
login: [AsyncFunction: login],
updateUser: [AsyncFunction: updateUser],
changePassword: [AsyncFunction: changePassword],
refreshTokens: [AsyncFunction: refreshTokens],
toggleAdmin: [AsyncFunction: toggleAdmin],
},
}
offline: Failure: Party was defined in resolvers, but it's not an object
Error: Party was defined in resolvers, but it's not an object
I am using serverless-offline, where this problem is coming from, and I haven't found any viable solutions.
This comes up when I run any query to the function. I also tried it without using merge from lodash, just one resolver, and it didn't work.
If anyone could offer any assistance that would be amazing!
Update: I've discovered this error comes up on the 2nd request I make, not the 1st, so then I figured it must be something to do the with the caching between lambda requests.
did you get success? im getting this error too! i cant use the same example as the documentation...
Same issue here. doing this basic example and still getting the error:
const { ApolloServer, gql } = require('apollo-server-lambda');
// Hardcoded data store
const books = [
{
title: 'Harry Potter and the Chamber of Secrets',
author: 'J.K. Rowling',
},
{
title: 'Jurassic Park',
author: 'Michael Crichton',
},
];
// Schema definition
const typeDefs = gql`
type Book {
title: String
author: String
}
type Query {
books: [Book]
}
`;
// Resolver map
const resolvers = {
Query: {
books() {
return books;
},
},
};
const server = new ApolloServer({ typeDefs, resolvers });
exports.handler = server.createHandler();
Unfortunately not - had to move away from serverless. I'm really stumped by this one.
Is it an issue with serverless version or the apollo-server-lambda?
Downgrading serverless-offline to 6.5.0 seems to fix this issue. They're recently released 6.7, one of the reason why this issue recently showed up in my project. 馃憤
@dnafication it worked here, thanks!
Lovely - always happy to point out a bug! Thanks team!
Most helpful comment
Downgrading
serverless-offlineto6.5.0seems to fix this issue. They're recently released6.7, one of the reason why this issue recently showed up in my project. 馃憤