|
1 | | -import { createContextPlugin } from "@webiny/handler"; |
2 | | -import type { Book, Context } from "~tests/types"; |
| 1 | +import type { Container } from "@webiny/di"; |
| 2 | +import { RequestContextInitializer } from "@webiny/event-handler-core"; |
| 3 | +import type { Book } from "~tests/types"; |
3 | 4 | import { CoreGraphQLSchemaFactory } from "~/graphql/abstractions.js"; |
4 | 5 | import type { GraphQLSchemaBuilder } from "~/features/GraphQLSchemaBuilder/abstractions.js"; |
5 | 6 |
|
@@ -90,15 +91,20 @@ export const BooksSchemaImpl = CoreGraphQLSchemaFactory.createImplementation({ |
90 | 91 | dependencies: [] |
91 | 92 | }); |
92 | 93 |
|
93 | | -export const booksCrudPlugin = createContextPlugin<Context>(async context => { |
94 | | - context.getBooks = async () => { |
95 | | - console.log("getBooks"); |
96 | | - console.table(books); |
97 | | - console.warn("Your store is quite empty!"); |
98 | | - return books; |
99 | | - }; |
100 | | -}); |
| 94 | +// Augments the request context with `getBooks` post-auth (the Query.books resolver reads it). |
| 95 | +export const booksCrudPlugin = (container: Container) => { |
| 96 | + container.registerInstance(RequestContextInitializer, { |
| 97 | + async init(context: Record<string, any>) { |
| 98 | + context.getBooks = async () => { |
| 99 | + console.log("getBooks"); |
| 100 | + console.table(books); |
| 101 | + console.warn("Your store is quite empty!"); |
| 102 | + return books; |
| 103 | + }; |
| 104 | + } |
| 105 | + }); |
| 106 | +}; |
101 | 107 |
|
102 | | -export const booksSchemaPlugin = createContextPlugin<Context>(context => { |
103 | | - context.container.register(BooksSchemaImpl); |
104 | | -}); |
| 108 | +export const booksSchemaPlugin = (container: Container) => { |
| 109 | + container.register(BooksSchemaImpl); |
| 110 | +}; |
0 commit comments