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