(resolverClass: Constructor<unknown>, resolverData: ResolverData<object>)
| 42 | export class LoopBackContainer implements ContainerType { |
| 43 | constructor(readonly ctx: Context) {} |
| 44 | get(resolverClass: Constructor<unknown>, resolverData: ResolverData<object>) { |
| 45 | debug('Resolving a resolver %s', resolverClass.name, resolverData); |
| 46 | |
| 47 | // Check if the resolverData has the LoopBack RequestContext |
| 48 | const graphQLCtx = resolverData.context as ExpressContextFunctionArgument; |
| 49 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 50 | const reqCtx = (graphQLCtx?.req as any)?.[MIDDLEWARE_CONTEXT]; |
| 51 | const parent = reqCtx ?? this.ctx; |
| 52 | |
| 53 | const resolutionCtx = new GraphQLResolutionContext( |
| 54 | parent, |
| 55 | resolverClass, |
| 56 | resolverData, |
| 57 | ); |
| 58 | if (reqCtx == null) { |
| 59 | resolutionCtx.scope = BindingScope.REQUEST; |
| 60 | } |
| 61 | const resolverBinding = createBindingFromClass(resolverClass, { |
| 62 | defaultNamespace: GraphQLBindings.RESOLVERS, |
| 63 | }); |
| 64 | // Find resolver bindings that match the class |
| 65 | const bindings = this.ctx |
| 66 | .findByTag(GraphQLTags.RESOLVER) |
| 67 | .filter(filterByServiceInterface(resolverClass)); |
| 68 | if (bindings.length === 0) { |
| 69 | // No explicit binding found |
| 70 | debug( |
| 71 | 'Resolver %s not found in context %s', |
| 72 | resolverClass.name, |
| 73 | this.ctx.name, |
| 74 | ); |
| 75 | // Let's use the resolution context to resolve it from the class |
| 76 | resolutionCtx.add(resolverBinding); |
| 77 | return resolutionCtx.getValueOrPromise(resolverBinding.key); |
| 78 | } |
| 79 | |
| 80 | let found: Readonly<Binding> | undefined; |
| 81 | if (bindings.length === 1) { |
| 82 | // Only one found, use it |
| 83 | found = bindings[0]; |
| 84 | } else { |
| 85 | // Narrow down by key |
| 86 | found = bindings.find(filterByKey(resolverBinding.key)); |
| 87 | if (!found) { |
| 88 | found = bindings[0]; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | debug( |
| 93 | 'Resolver %s found in context %s', |
| 94 | resolverClass.name, |
| 95 | resolutionCtx.name, |
| 96 | found, |
| 97 | ); |
| 98 | return resolutionCtx.getValueOrPromise(found.key); |
| 99 | } |
| 100 | } |
nothing calls this directly
no test coverage detected