-
Notifications
You must be signed in to change notification settings - Fork 2k
/
ApolloServer.ts
31 lines (27 loc) 路 1.2 KB
/
ApolloServer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { graphqlCloudflare } from './cloudflareApollo';
import { ApolloServerBase } from 'apollo-server-core';
export { GraphQLOptions, GraphQLExtension } from 'apollo-server-core';
import { GraphQLOptions } from 'apollo-server-core';
import { Request } from 'apollo-server-env';
export class ApolloServer extends ApolloServerBase {
// This translates the arguments from the middleware into graphQL options It
// provides typings for the integration specific behavior, ideally this would
// be propagated with a generic to the super class
async createGraphQLServerOptions(request: Request): Promise<GraphQLOptions> {
return super.graphQLServerOptions({ request });
}
public async listen() {
// In case the user didn't bother to call and await the `start` method, we
// kick it off in the background (with any errors getting logged
// and also rethrown from graphQLServerOptions during later requests).
this.ensureStarting();
addEventListener('fetch', (event: FetchEvent) => {
event.respondWith(
graphqlCloudflare(() => {
return this.createGraphQLServerOptions(event.request);
})(event.request),
);
});
return await { url: '', port: null };
}
}