@solana/rpc-graphql 2.0.0-experimental.b419cd0 → 2.0.0-experimental.b7674ea

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.
@@ -127,15 +127,14 @@ function createAccountLoader(rpc) {
127
127
  }
128
128
  };
129
129
  }
130
-
131
- // src/loaders/transaction.ts
132
130
  function normalizeArgs2(args) {
133
- const { commitment, encoding } = args;
131
+ const { commitment, encoding, signature } = args;
134
132
  return {
135
133
  commitment: commitment ?? "confirmed",
136
134
  encoding: encoding ?? "jsonParsed",
137
135
  // Always use 0 to avoid silly errors
138
- maxSupportedTransactionVersion: 0
136
+ maxSupportedTransactionVersion: 0,
137
+ signature
139
138
  };
140
139
  }
141
140
  function refineJsonParsedInstructionData(jsonParsedInstructionData) {
@@ -188,21 +187,16 @@ function refineJsonParsedTransaction({ encoding, transaction }) {
188
187
  function processQueryResponse2({ encoding, transaction }) {
189
188
  return refineJsonParsedTransaction({ encoding, transaction });
190
189
  }
191
- async function loadTransaction({ signature, ...config }, cache, rpc, _info) {
192
- const requestConfig = normalizeArgs2(config);
193
- const { encoding } = requestConfig;
194
- const cached = cache.get(signature, requestConfig);
195
- if (cached !== null) {
196
- return cached;
197
- }
198
- let transaction = await rpc.getTransaction(signature, requestConfig).send().catch((e) => {
190
+ async function loadTransaction(rpc, { signature, ...config }) {
191
+ const { encoding } = config;
192
+ let transaction = await rpc.getTransaction(signature, config).send().catch((e) => {
199
193
  throw e;
200
194
  });
201
195
  if (transaction === null) {
202
196
  return null;
203
197
  }
204
198
  if (encoding !== "jsonParsed") {
205
- const transactionJsonParsed = await rpc.getTransaction(signature, requestConfig).send().catch((e) => {
199
+ const transactionJsonParsed = await rpc.getTransaction(signature, config).send().catch((e) => {
206
200
  throw e;
207
201
  });
208
202
  if (transactionJsonParsed === null) {
@@ -215,9 +209,25 @@ async function loadTransaction({ signature, ...config }, cache, rpc, _info) {
215
209
  };
216
210
  }
217
211
  const queryResponse = processQueryResponse2({ encoding, transaction });
218
- cache.insert(signature, requestConfig, queryResponse);
219
212
  return queryResponse;
220
213
  }
214
+ function createTransactionBatchLoadFn(rpc) {
215
+ const resolveTransactionUsingRpc = loadTransaction.bind(null, rpc);
216
+ return async (transactionQueryArgs) => {
217
+ return await Promise.all(transactionQueryArgs.map(async (args) => await resolveTransactionUsingRpc(args)));
218
+ };
219
+ }
220
+ function createTransactionLoader(rpc) {
221
+ const loader = new DataLoader__default.default(createTransactionBatchLoadFn(rpc), { cacheKeyFn: fastStableStringify__default.default });
222
+ return {
223
+ load: async (args, info) => {
224
+ if (onlyPresentFieldRequested("signature", info)) {
225
+ return { signature: args.signature };
226
+ }
227
+ return loader.load(normalizeArgs2(args));
228
+ }
229
+ };
230
+ }
221
231
 
222
232
  // src/loaders/block.ts
223
233
  function normalizeArgs3(args) {
@@ -342,25 +352,28 @@ async function loadProgramAccounts({ programAddress, ...config }, cache, rpc, _i
342
352
  }
343
353
 
344
354
  // src/context.ts
355
+ function createRpcGraphQLLoaders(rpc) {
356
+ return {
357
+ account: createAccountLoader(rpc),
358
+ block: createBlockLoader(rpc),
359
+ transaction: createTransactionLoader(rpc)
360
+ };
361
+ }
345
362
  function createSolanaGraphQLContext(rpc) {
346
363
  const cache = createGraphQLCache();
347
364
  return {
348
- accountLoader: createAccountLoader(rpc),
349
- blockLoader: createBlockLoader(rpc),
350
365
  cache,
351
366
  loadProgramAccounts(args, info) {
352
367
  return loadProgramAccounts(args, this.cache, this.rpc);
353
368
  },
354
- loadTransaction(args, info) {
355
- return loadTransaction(args, this.cache, this.rpc);
356
- },
369
+ loaders: createRpcGraphQLLoaders(rpc),
357
370
  rpc
358
371
  };
359
372
  }
360
373
 
361
374
  // src/resolvers/account.ts
362
375
  var resolveAccount = (fieldName) => {
363
- return (parent, args, context, info) => parent[fieldName] === null ? null : context.accountLoader.load({ ...args, address: parent[fieldName] }, info);
376
+ return (parent, args, context, info) => parent[fieldName] === null ? null : context.loaders.account.load({ ...args, address: parent[fieldName] }, info);
364
377
  };
365
378
 
366
379
  // src/schema/account.ts
@@ -2994,16 +3007,16 @@ var schemaTypeDefs = (
2994
3007
  var schemaResolvers = {
2995
3008
  Query: {
2996
3009
  account(_, args, context, info) {
2997
- return context.accountLoader.load(args, info);
3010
+ return context.loaders.account.load(args, info);
2998
3011
  },
2999
3012
  block(_, args, context, info) {
3000
- return context.blockLoader.load(args, info);
3013
+ return context.loaders.block.load(args, info);
3001
3014
  },
3002
3015
  programAccounts(_, args, context, info) {
3003
3016
  return context.loadProgramAccounts(args, info);
3004
3017
  },
3005
3018
  transaction(_, args, context, info) {
3006
- return context.loadTransaction(args, info);
3019
+ return context.loaders.transaction.load(args, info);
3007
3020
  }
3008
3021
  }
3009
3022
  };