@solana/rpc-graphql 2.0.0-experimental.aa4a701 → 2.0.0-experimental.b419cd0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.cjs +24 -14
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +24 -14
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +24 -14
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +24 -14
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +24 -14
- package/dist/index.node.js.map +1 -1
- package/dist/types/context.d.ts +1 -2
- package/dist/types/loaders/block.d.ts +12 -2
- package/package.json +7 -7
package/dist/index.node.cjs
CHANGED
|
@@ -217,12 +217,13 @@ async function loadTransaction({ signature, ...config }, cache, rpc, _info) {
|
|
|
217
217
|
|
|
218
218
|
// src/loaders/block.ts
|
|
219
219
|
function normalizeArgs3(args) {
|
|
220
|
-
const { commitment, encoding, transactionDetails } = args;
|
|
220
|
+
const { commitment, encoding, slot, transactionDetails } = args;
|
|
221
221
|
return {
|
|
222
222
|
commitment: commitment ?? "confirmed",
|
|
223
223
|
encoding: encoding ?? "jsonParsed",
|
|
224
224
|
// Always use 0 to avoid silly errors
|
|
225
225
|
maxSupportedTransactionVersion: 0,
|
|
226
|
+
slot,
|
|
226
227
|
transactionDetails: transactionDetails ?? "full"
|
|
227
228
|
};
|
|
228
229
|
}
|
|
@@ -257,23 +258,34 @@ function processQueryResponse3({
|
|
|
257
258
|
transactionDetails
|
|
258
259
|
};
|
|
259
260
|
}
|
|
260
|
-
async function loadBlock({ slot, ...config }
|
|
261
|
-
const
|
|
262
|
-
const
|
|
263
|
-
const cached = cache.get(slot, config);
|
|
264
|
-
if (cached !== null) {
|
|
265
|
-
return cached;
|
|
266
|
-
}
|
|
267
|
-
const block = await rpc.getBlock(slot, requestConfig).send().catch((e) => {
|
|
261
|
+
async function loadBlock(rpc, { slot, ...config }) {
|
|
262
|
+
const { encoding, transactionDetails } = config;
|
|
263
|
+
const block = await rpc.getBlock(slot, config).send().catch((e) => {
|
|
268
264
|
throw e;
|
|
269
265
|
});
|
|
270
266
|
if (block === null) {
|
|
271
267
|
return { slot };
|
|
272
268
|
}
|
|
273
269
|
const queryResponse = processQueryResponse3({ block, encoding, transactionDetails });
|
|
274
|
-
cache.insert(slot, requestConfig, queryResponse);
|
|
275
270
|
return queryResponse;
|
|
276
271
|
}
|
|
272
|
+
function createBlockBatchLoadFn(rpc) {
|
|
273
|
+
const resolveBlockUsingRpc = loadBlock.bind(null, rpc);
|
|
274
|
+
return async (blockQueryArgs) => {
|
|
275
|
+
return await Promise.all(blockQueryArgs.map(async (args) => await resolveBlockUsingRpc(args)));
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function createBlockLoader(rpc) {
|
|
279
|
+
const loader = new DataLoader__default.default(createBlockBatchLoadFn(rpc), { cacheKeyFn: fastStableStringify__default.default });
|
|
280
|
+
return {
|
|
281
|
+
load: async (args, info) => {
|
|
282
|
+
if (onlyPresentFieldRequested("slot", info)) {
|
|
283
|
+
return { slot: args.slot };
|
|
284
|
+
}
|
|
285
|
+
return loader.load(normalizeArgs3(args));
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
277
289
|
|
|
278
290
|
// src/loaders/program-accounts.ts
|
|
279
291
|
function normalizeArgs4(args) {
|
|
@@ -330,10 +342,8 @@ function createSolanaGraphQLContext(rpc) {
|
|
|
330
342
|
const cache = createGraphQLCache();
|
|
331
343
|
return {
|
|
332
344
|
accountLoader: createAccountLoader(rpc),
|
|
345
|
+
blockLoader: createBlockLoader(rpc),
|
|
333
346
|
cache,
|
|
334
|
-
loadBlock(args, info) {
|
|
335
|
-
return loadBlock(args, this.cache, this.rpc);
|
|
336
|
-
},
|
|
337
347
|
loadProgramAccounts(args, info) {
|
|
338
348
|
return loadProgramAccounts(args, this.cache, this.rpc);
|
|
339
349
|
},
|
|
@@ -2983,7 +2993,7 @@ var schemaResolvers = {
|
|
|
2983
2993
|
return context.accountLoader.load(args, info);
|
|
2984
2994
|
},
|
|
2985
2995
|
block(_, args, context, info) {
|
|
2986
|
-
return context.
|
|
2996
|
+
return context.blockLoader.load(args, info);
|
|
2987
2997
|
},
|
|
2988
2998
|
programAccounts(_, args, context, info) {
|
|
2989
2999
|
return context.loadProgramAccounts(args, info);
|