MCPcopy Create free account
hub / github.com/dagger/dagger / constructor

Method constructor

sdk/typescript/src/module/executor.ts:146–244  ·  view source on GitHub ↗
(
    private readonly executor: Executor,
    private readonly module: DaggerModule,
    private readonly ifaceName: string,
    private readonly ifaceId: string,
    private readonly fcts: DaggerInterfaceFunctions,
  )

Source from the content-addressed store, hash-verified

144 private _ctx: Context
145
146 constructor(
147 private readonly executor: Executor,
148 private readonly module: DaggerModule,
149 private readonly ifaceName: string,
150 private readonly ifaceId: string,
151 private readonly fcts: DaggerInterfaceFunctions,
152 ) {
153 this._ctx = new Context([], new Connection(dag.getGQLClient()))
154
155 // Load the interface by its identifier via node(id:)
156 this._ctx = this._ctx.selectNode(ifaceId, ifaceName)
157
158 Object.entries(fcts).forEach(([name, fct]) => {
159 const argKeys = Object.keys(fct.arguments)
160
161 // Dynamically adding functions of the interface and it's resolvers.
162 // @ts-ignore
163 this[name] = async (...args: any[]) => {
164 // Fill up arguments of that function.
165 const argsPayload = {}
166 for (let i = 0; i < argKeys.length; i++) {
167 if (args[i] !== undefined) {
168 // @ts-ignore
169 argsPayload[argKeys[i]] = args[i]
170 }
171 }
172
173 this._ctx = this._ctx.select(name, argsPayload)
174
175 // If the function is returning an IDable, we don't need to execute it
176 // since it will be resolved later.
177 if (
178 fct.returnType!.kind === TypeDefKind.InterfaceKind ||
179 fct.returnType!.kind === TypeDefKind.ObjectKind
180 ) {
181 return this
182 }
183
184 // If the function is returning a list, we may need to load the sub-objects
185 if (fct.returnType!.kind === TypeDefKind.ListKind) {
186 const listTypeDef = (fct.returnType as TypeDef<TypeDefKind.ListKind>)
187 .typeDef
188
189 // If the list is an object or an interface, then we need to load the sub-objects.
190 if (
191 listTypeDef.kind === TypeDefKind.ObjectKind ||
192 listTypeDef.kind === TypeDefKind.InterfaceKind
193 ) {
194 const typedef = listTypeDef as
195 | TypeDef<TypeDefKind.ObjectKind>
196 | TypeDef<TypeDefKind.InterfaceKind>
197
198 // Resolves the call to get the list of IDs to load
199 const ids = await this._ctx
200 .select("id")
201 .execute<Array<{ id: string }>>()
202
203 // If the return type is an interface defined by that module, we need to load it through

Callers

nothing calls this directly

Calls 6

selectNodeMethod · 0.80
keysMethod · 0.80
getGQLClientMethod · 0.45
entriesMethod · 0.45
selectMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected