Skip to content

Commit

Permalink
fix examples for micro
Browse files Browse the repository at this point in the history
hooray for vercel/micro#335
  • Loading branch information
glasser committed Mar 16, 2021
1 parent 9ea8067 commit ec51e85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/apollo-server-core/src/ApolloServer.ts
Expand Up @@ -1172,6 +1172,8 @@ export class ApolloServerBase {
// (and they're not using `apollo-server` which does that for you). First
// we log the error that prevented startup (which means it will get logged
// once for every GraphQL operation).
// FIXME the message this error prints is inaccurate in the "shutting down"
// case.
this.logStartupError(err);
// Now make the operation itself fail.
// We intentionally do not re-throw actual startup error as it may contain
Expand Down
32 changes: 17 additions & 15 deletions packages/apollo-server-micro/README.md
Expand Up @@ -35,8 +35,7 @@ const resolvers = {
};

const apolloServer = new ApolloServer({ typeDefs, resolvers });
await server.start();
module.exports = apolloServer.createHandler();
module.exports = apolloServer.start().then(() => apolloServer.createHandler());
```

3) `package.json`
Expand Down Expand Up @@ -87,9 +86,10 @@ const resolvers = {
};

const apolloServer = new ApolloServer({ typeDefs, resolvers });
await server.start();
const handler = apolloServer.createHandler(); // highlight-line
module.exports = cors((req, res) => req.method === 'OPTIONS' ? res.end() : handler(req, res)) // highlight-line
module.exports = apolloServer.start().then(() => {
const handler = apolloServer.createHandler(); // highlight-line
return cors((req, res) => req.method === 'OPTIONS' ? res.end() : handler(req, res)) // highlight-line
});
```

3) `package.json`
Expand Down Expand Up @@ -139,8 +139,9 @@ const resolvers = {
};

const apolloServer = new ApolloServer({ typeDefs, resolvers });
await server.start();
module.exports = apolloServer.createHandler({ path: '/data' }); // highlight-line
module.exports = apolloServer.start().then(() => {
return apolloServer.createHandler({ path: '/data' }); // highlight-line
});
```

3) `package.json`
Expand Down Expand Up @@ -192,14 +193,15 @@ const resolvers = {
};
const apolloServer = new ApolloServer({ typeDefs, resolvers });
await server.start();
const graphqlPath = '/data';
const graphqlHandler = apolloServer.createHandler({ path: graphqlPath });
module.exports = router(
get('/', (req, res) => 'Welcome!'),
post(graphqlPath, graphqlHandler),
get(graphqlPath, graphqlHandler),
);
module.exports = apolloServer.start().then(() => {
const graphqlPath = '/data';
const graphqlHandler = apolloServer.createHandler({ path: graphqlPath });
return router(
get('/', (req, res) => 'Welcome!'),
post(graphqlPath, graphqlHandler),
get(graphqlPath, graphqlHandler),
);
});
```

3) `package.json`
Expand Down

0 comments on commit ec51e85

Please sign in to comment.