@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.
@@ -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 }, cache, rpc, _info) {
261
- const requestConfig = normalizeArgs3(config);
262
- const { encoding, transactionDetails } = requestConfig;
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.loadBlock(args, info);
2996
+ return context.blockLoader.load(args, info);
2987
2997
  },
2988
2998
  programAccounts(_, args, context, info) {
2989
2999
  return context.loadProgramAccounts(args, info);