Skip to content

Commit

Permalink
fix: add isColdStart to request context
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Apr 29, 2020
1 parent c2486e5 commit 7807688
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ function normalizeEvent(event) {
}

let cache;
let isColdStart = true;

const plugin: CreateApolloHandlerPlugin = {
name: "handler-apollo-server-create-handler",
type: "handler-apollo-server-create-handler",
async create({ context, options }) {
if (cache) {
isColdStart = false;
return cache;
}

Expand Down Expand Up @@ -46,7 +48,8 @@ const plugin: CreateApolloHandlerPlugin = {
schema,
context: async ({ event }) => ({
event,
plugins: context.plugins
plugins: context.plugins,
isColdStart
})
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default (options: HttpHandlerApolloServerOptions = {}): HttpHandlerPlugin
},
async handle({ args, context }) {
const [event, handlerContext] = args;

try {
const createApolloHandlerPlugin = context.plugins.byName<CreateApolloHandlerPlugin>(
"handler-apollo-server-create-handler"
Expand Down
2 changes: 1 addition & 1 deletion packages/http-handler-apollo-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export type CreateApolloHandlerPlugin = Plugin & {
export type CreateSchemaPlugin = Plugin & {
name: "handler-apollo-server-create-schema";
type: "handler-apollo-server-create-schema";
create(params: { plugins: PluginsContainer }): { schema: GraphQLSchema };
create(params: { plugins: PluginsContainer; }): { schema: GraphQLSchema };
};

0 comments on commit 7807688

Please sign in to comment.