Skip to content

Commit

Permalink
Fix generateNextGraphqlAPI experimental option (#7069)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Dec 15, 2021
1 parent 0fd9967 commit c51f8f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-beers-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Fixed `You must await server.start() before calling server.createHandler()` error when using the `generateNextGraphqlAPI` experimental option.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { ApolloServer } from 'apollo-server-micro';
import { KeystoneConfig } from '../types';
import { initConfig } from '../lib/config/initConfig';
import { createSystem } from '../lib/createSystem';
import { createApolloServerMicro } from '../lib/server/createApolloServer';

export function nextGraphQLAPIRoute(keystoneConfig: KeystoneConfig, prismaClient: any) {
type Handler = ReturnType<ApolloServer['createHandler']>;

export function nextGraphQLAPIRoute(keystoneConfig: KeystoneConfig, prismaClient: any): Handler {
const initializedKeystoneConfig = initConfig(keystoneConfig);
const { graphQLSchema, getKeystone } = createSystem(initializedKeystoneConfig);

Expand All @@ -19,5 +22,13 @@ export function nextGraphQLAPIRoute(keystoneConfig: KeystoneConfig, prismaClient
connectionPromise: keystone.connect(),
});

return apolloServer.createHandler({ path: keystoneConfig.graphql?.path || '/api/graphql' });
let startPromise = apolloServer.start();

return async (req, res) => {
await startPromise;
return apolloServer.createHandler({ path: keystoneConfig.graphql?.path || '/api/graphql' })(
req,
res
);
};
}

0 comments on commit c51f8f7

Please sign in to comment.