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