|
1 | 1 | import { describe, test, expect } from "vitest"; |
2 | 2 | import useGqlHandler from "./useGqlHandler"; |
3 | 3 | import { booksSchemaPlugin, booksCrudPlugin } from "~tests/mocks/booksSchema"; |
4 | | -import { GraphQLResolverDecorators } from "~/graphql/abstractions"; |
| 4 | +import { GraphQLResolverDecoratorsFactory } from "~/graphql/abstractions"; |
5 | 5 | import { createContextPlugin } from "@webiny/handler"; |
6 | 6 | import type { Context } from "./types"; |
7 | 7 |
|
@@ -90,62 +90,68 @@ describe("GraphQL Handler", () => { |
90 | 90 |
|
91 | 91 | test("should compose resolvers", async () => { |
92 | 92 | // Create decorator implementations |
93 | | - class LowerCaseNameDecorator implements GraphQLResolverDecorators.Interface { |
94 | | - getDecorators() { |
95 | | - return { |
96 | | - "Book.name": [ |
97 | | - (resolver: any) => |
98 | | - async (parent: any, args: any, context: any, info: any) => { |
99 | | - const name = (await resolver( |
100 | | - parent, |
101 | | - args, |
102 | | - context, |
103 | | - info |
104 | | - )) as string; |
105 | | - return name.toLowerCase(); |
106 | | - } |
107 | | - ] |
108 | | - }; |
| 93 | + class LowerCaseNameDecorator implements GraphQLResolverDecoratorsFactory.Interface { |
| 94 | + execute() { |
| 95 | + return [ |
| 96 | + { |
| 97 | + "Book.name": [ |
| 98 | + (resolver: any) => |
| 99 | + async (parent: any, args: any, context: any, info: any) => { |
| 100 | + const name = (await resolver( |
| 101 | + parent, |
| 102 | + args, |
| 103 | + context, |
| 104 | + info |
| 105 | + )) as string; |
| 106 | + return name.toLowerCase(); |
| 107 | + } |
| 108 | + ] |
| 109 | + } |
| 110 | + ]; |
109 | 111 | } |
110 | 112 | } |
111 | 113 |
|
112 | | - class ListBooksDecorator implements GraphQLResolverDecorators.Interface { |
113 | | - getDecorators() { |
114 | | - return { |
115 | | - "Query.books": [ |
116 | | - () => async () => { |
117 | | - return [{ name: "Article 1" }]; |
118 | | - } |
119 | | - ] |
120 | | - }; |
| 114 | + class ListBooksDecorator implements GraphQLResolverDecoratorsFactory.Interface { |
| 115 | + execute() { |
| 116 | + return [ |
| 117 | + { |
| 118 | + "Query.books": [ |
| 119 | + () => async () => { |
| 120 | + return [{ name: "Article 1" }]; |
| 121 | + } |
| 122 | + ] |
| 123 | + } |
| 124 | + ]; |
121 | 125 | } |
122 | 126 | } |
123 | 127 |
|
124 | | - class AddNameSuffixDecorator implements GraphQLResolverDecorators.Interface { |
125 | | - getDecorators() { |
126 | | - return { |
127 | | - "Book.name": [ |
128 | | - (resolver: any) => |
129 | | - async (...args: any[]) => { |
130 | | - const name = await resolver(...args); |
131 | | - return `${name} (suffix)`; |
132 | | - } |
133 | | - ] |
134 | | - }; |
| 128 | + class AddNameSuffixDecorator implements GraphQLResolverDecoratorsFactory.Interface { |
| 129 | + execute() { |
| 130 | + return [ |
| 131 | + { |
| 132 | + "Book.name": [ |
| 133 | + (resolver: any) => |
| 134 | + async (...args: any[]) => { |
| 135 | + const name = await resolver(...args); |
| 136 | + return `${name} (suffix)`; |
| 137 | + } |
| 138 | + ] |
| 139 | + } |
| 140 | + ]; |
135 | 141 | } |
136 | 142 | } |
137 | 143 |
|
138 | | - const LowerCaseNameDecoratorImpl = GraphQLResolverDecorators.createImplementation({ |
| 144 | + const LowerCaseNameDecoratorImpl = GraphQLResolverDecoratorsFactory.createImplementation({ |
139 | 145 | implementation: LowerCaseNameDecorator, |
140 | 146 | dependencies: [] |
141 | 147 | }); |
142 | 148 |
|
143 | | - const ListBooksDecoratorImpl = GraphQLResolverDecorators.createImplementation({ |
| 149 | + const ListBooksDecoratorImpl = GraphQLResolverDecoratorsFactory.createImplementation({ |
144 | 150 | implementation: ListBooksDecorator, |
145 | 151 | dependencies: [] |
146 | 152 | }); |
147 | 153 |
|
148 | | - const AddNameSuffixDecoratorImpl = GraphQLResolverDecorators.createImplementation({ |
| 154 | + const AddNameSuffixDecoratorImpl = GraphQLResolverDecoratorsFactory.createImplementation({ |
149 | 155 | implementation: AddNameSuffixDecorator, |
150 | 156 | dependencies: [] |
151 | 157 | }); |
|
0 commit comments