MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / get

Method get

extensions/graphql/src/graphql.container.ts:44–99  ·  view source on GitHub ↗
(resolverClass: Constructor<unknown>, resolverData: ResolverData<object>)

Source from the content-addressed store, hash-verified

42export 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}

Callers

nothing calls this directly

Calls 7

filterByServiceInterfaceFunction · 0.90
createBindingFromClassFunction · 0.85
filterByKeyFunction · 0.85
findByTagMethod · 0.80
getValueOrPromiseMethod · 0.80
addMethod · 0.65
findMethod · 0.65

Tested by

no test coverage detected