Meteor skeleton has been updated for Apollo 3 in the upcoming Meteor 2.4 release. If you want to try it out give the beta a try. Prior to Meteor 2.4 the skeleton uses Apollo 2, so if you want to use the latest Apollo you need to make the necessary upgrades.
These should be:
All resolvers and queries should be async
functions.
const resolvers = {
Query: {
getLink: async (obj, { id }) => LinksCollection.findOne(id),
getLinks: async () => LinksCollection.find().fetch()
}
};
Add express as a dependency to your app.
Change your server Apollo start to:
// apollo.js
import { ApolloServer } from 'apollo-server-express';
import { WebApp } from 'meteor/webapp';
import { getUser } from 'meteor/apollo';
import { makeExecutableSchema } from '@graphql-tools/schema';
const server = new ApolloServer({
schema: makeExecutableSchema({
typeDefs,
resolvers,
}),
context: async ({ req }) => ({
user: await getUser(req.headers.authorization)
})
})
export async function startApolloServer() {
await server.start();
const app = WebApp.connectHandlers;
server.applyMiddleware({
app,
cors: true
});
}
// main.js
import { startApolloServer } from './apollo';
function insertLink({ title, url }) {
LinksCollection.insert({title, url, createdAt: new Date()});
}
try {
startApolloServer().then();
} catch (e) {
console.error(e.reason);
}