(client: Client, logEmitter?: LogEmitter)
| 71 | private logEmitter?: LogEmitter |
| 72 | |
| 73 | constructor(client: Client, logEmitter?: LogEmitter) { |
| 74 | this.logEmitter = logEmitter |
| 75 | this.client = client |
| 76 | |
| 77 | this.dataloader = new DataLoader({ |
| 78 | batchLoader: createApplyBatchExtensionsFunction(async ({ requests, customDataProxyFetch }) => { |
| 79 | const { transaction, otelParentCtx } = requests[0] |
| 80 | const queries = requests.map((r) => r.protocolQuery) |
| 81 | const traceparent = this.client._tracingHelper.getTraceParent(otelParentCtx) |
| 82 | |
| 83 | // TODO: pass the child information to QE for it to issue links to queries |
| 84 | // const links = requests.map((r) => trace.getSpanContext(r.otelChildCtx!)) |
| 85 | |
| 86 | const containsWrite = requests.some((r) => isWrite(r.protocolQuery.action)) |
| 87 | |
| 88 | const results = await this.client._engine.requestBatch(queries, { |
| 89 | traceparent, |
| 90 | transaction: getTransactionOptions(transaction), |
| 91 | containsWrite, |
| 92 | customDataProxyFetch, |
| 93 | }) |
| 94 | |
| 95 | return results.map((result, i) => { |
| 96 | if (result instanceof Error) { |
| 97 | return result |
| 98 | } |
| 99 | |
| 100 | try { |
| 101 | return this.mapQueryEngineResult(requests[i], result) |
| 102 | } catch (error) { |
| 103 | return error |
| 104 | } |
| 105 | }) |
| 106 | }), |
| 107 | |
| 108 | singleLoader: async (request) => { |
| 109 | const interactiveTransaction = |
| 110 | request.transaction?.kind === 'itx' ? getItxTransactionOptions(request.transaction) : undefined |
| 111 | |
| 112 | const response = await this.client._engine.request(request.protocolQuery, { |
| 113 | traceparent: this.client._tracingHelper.getTraceParent(), |
| 114 | interactiveTransaction, |
| 115 | isWrite: isWrite(request.protocolQuery.action), |
| 116 | customDataProxyFetch: request.customDataProxyFetch, |
| 117 | }) |
| 118 | return this.mapQueryEngineResult(request, response) |
| 119 | }, |
| 120 | |
| 121 | batchBy: (request) => { |
| 122 | // If the request is part of an interactive transaction, we want to group all requests with the same |
| 123 | // protocolQuery together to take advantage of automatic batching in the engine. |
| 124 | // Note that we only do this for interactive transactions, not for batch transactions, as it can lead to queries |
| 125 | // being executed out of order in batch transactions. |
| 126 | if (request.transaction?.kind === 'itx') { |
| 127 | const batchId = getBatchId(request.protocolQuery) |
| 128 | return `itx-${request.transaction.id}${batchId ? `-${batchId}` : ''}` |
| 129 | } |
| 130 |
nothing calls this directly
no test coverage detected