@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.
@@ -210,12 +210,13 @@ async function loadTransaction({ signature, ...config }, cache, rpc, _info) {
210
210
 
211
211
  // src/loaders/block.ts
212
212
  function normalizeArgs3(args) {
213
- const { commitment, encoding, transactionDetails } = args;
213
+ const { commitment, encoding, slot, transactionDetails } = args;
214
214
  return {
215
215
  commitment: commitment ?? "confirmed",
216
216
  encoding: encoding ?? "jsonParsed",
217
217
  // Always use 0 to avoid silly errors
218
218
  maxSupportedTransactionVersion: 0,
219
+ slot,
219
220
  transactionDetails: transactionDetails ?? "full"
220
221
  };
221
222
  }
@@ -250,23 +251,34 @@ function processQueryResponse3({
250
251
  transactionDetails
251
252
  };
252
253
  }
253
- async function loadBlock({ slot, ...config }, cache, rpc, _info) {
254
- const requestConfig = normalizeArgs3(config);
255
- const { encoding, transactionDetails } = requestConfig;
256
- const cached = cache.get(slot, config);
257
- if (cached !== null) {
258
- return cached;
259
- }
260
- const block = await rpc.getBlock(slot, requestConfig).send().catch((e) => {
254
+ async function loadBlock(rpc, { slot, ...config }) {
255
+ const { encoding, transactionDetails } = config;
256
+ const block = await rpc.getBlock(slot, config).send().catch((e) => {
261
257
  throw e;
262
258
  });
263
259
  if (block === null) {
264
260
  return { slot };
265
261
  }
266
262
  const queryResponse = processQueryResponse3({ block, encoding, transactionDetails });
267
- cache.insert(slot, requestConfig, queryResponse);
268
263
  return queryResponse;
269
264
  }
265
+ function createBlockBatchLoadFn(rpc) {
266
+ const resolveBlockUsingRpc = loadBlock.bind(null, rpc);
267
+ return async (blockQueryArgs) => {
268
+ return await Promise.all(blockQueryArgs.map(async (args) => await resolveBlockUsingRpc(args)));
269
+ };
270
+ }
271
+ function createBlockLoader(rpc) {
272
+ const loader = new DataLoader(createBlockBatchLoadFn(rpc), { cacheKeyFn: fastStableStringify });
273
+ return {
274
+ load: async (args, info) => {
275
+ if (onlyPresentFieldRequested("slot", info)) {
276
+ return { slot: args.slot };
277
+ }
278
+ return loader.load(normalizeArgs3(args));
279
+ }
280
+ };
281
+ }
270
282
 
271
283
  // src/loaders/program-accounts.ts
272
284
  function normalizeArgs4(args) {
@@ -323,10 +335,8 @@ function createSolanaGraphQLContext(rpc) {
323
335
  const cache = createGraphQLCache();
324
336
  return {
325
337
  accountLoader: createAccountLoader(rpc),
338
+ blockLoader: createBlockLoader(rpc),
326
339
  cache,
327
- loadBlock(args, info) {
328
- return loadBlock(args, this.cache, this.rpc);
329
- },
330
340
  loadProgramAccounts(args, info) {
331
341
  return loadProgramAccounts(args, this.cache, this.rpc);
332
342
  },
@@ -2976,7 +2986,7 @@ var schemaResolvers = {
2976
2986
  return context.accountLoader.load(args, info);
2977
2987
  },
2978
2988
  block(_, args, context, info) {
2979
- return context.loadBlock(args, info);
2989
+ return context.blockLoader.load(args, info);
2980
2990
  },
2981
2991
  programAccounts(_, args, context, info) {
2982
2992
  return context.loadProgramAccounts(args, info);