@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.
- package/dist/index.browser.cjs +24 -14
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +24 -14
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +24 -14
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +24 -14
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +24 -14
- package/dist/index.node.js.map +1 -1
- package/dist/types/context.d.ts +1 -2
- package/dist/types/loaders/block.d.ts +12 -2
- package/package.json +7 -7
package/dist/index.browser.cjs
CHANGED
|
@@ -221,12 +221,13 @@ async function loadTransaction({ signature, ...config }, cache, rpc, _info) {
|
|
|
221
221
|
|
|
222
222
|
// src/loaders/block.ts
|
|
223
223
|
function normalizeArgs3(args) {
|
|
224
|
-
const { commitment, encoding, transactionDetails } = args;
|
|
224
|
+
const { commitment, encoding, slot, transactionDetails } = args;
|
|
225
225
|
return {
|
|
226
226
|
commitment: commitment ?? "confirmed",
|
|
227
227
|
encoding: encoding ?? "jsonParsed",
|
|
228
228
|
// Always use 0 to avoid silly errors
|
|
229
229
|
maxSupportedTransactionVersion: 0,
|
|
230
|
+
slot,
|
|
230
231
|
transactionDetails: transactionDetails ?? "full"
|
|
231
232
|
};
|
|
232
233
|
}
|
|
@@ -261,23 +262,34 @@ function processQueryResponse3({
|
|
|
261
262
|
transactionDetails
|
|
262
263
|
};
|
|
263
264
|
}
|
|
264
|
-
async function loadBlock({ slot, ...config }
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
const cached = cache.get(slot, config);
|
|
268
|
-
if (cached !== null) {
|
|
269
|
-
return cached;
|
|
270
|
-
}
|
|
271
|
-
const block = await rpc.getBlock(slot, requestConfig).send().catch((e) => {
|
|
265
|
+
async function loadBlock(rpc, { slot, ...config }) {
|
|
266
|
+
const { encoding, transactionDetails } = config;
|
|
267
|
+
const block = await rpc.getBlock(slot, config).send().catch((e) => {
|
|
272
268
|
throw e;
|
|
273
269
|
});
|
|
274
270
|
if (block === null) {
|
|
275
271
|
return { slot };
|
|
276
272
|
}
|
|
277
273
|
const queryResponse = processQueryResponse3({ block, encoding, transactionDetails });
|
|
278
|
-
cache.insert(slot, requestConfig, queryResponse);
|
|
279
274
|
return queryResponse;
|
|
280
275
|
}
|
|
276
|
+
function createBlockBatchLoadFn(rpc) {
|
|
277
|
+
const resolveBlockUsingRpc = loadBlock.bind(null, rpc);
|
|
278
|
+
return async (blockQueryArgs) => {
|
|
279
|
+
return await Promise.all(blockQueryArgs.map(async (args) => await resolveBlockUsingRpc(args)));
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function createBlockLoader(rpc) {
|
|
283
|
+
const loader = new DataLoader__default.default(createBlockBatchLoadFn(rpc), { cacheKeyFn: fastStableStringify__default.default });
|
|
284
|
+
return {
|
|
285
|
+
load: async (args, info) => {
|
|
286
|
+
if (onlyPresentFieldRequested("slot", info)) {
|
|
287
|
+
return { slot: args.slot };
|
|
288
|
+
}
|
|
289
|
+
return loader.load(normalizeArgs3(args));
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
281
293
|
|
|
282
294
|
// src/loaders/program-accounts.ts
|
|
283
295
|
function normalizeArgs4(args) {
|
|
@@ -334,10 +346,8 @@ function createSolanaGraphQLContext(rpc) {
|
|
|
334
346
|
const cache = createGraphQLCache();
|
|
335
347
|
return {
|
|
336
348
|
accountLoader: createAccountLoader(rpc),
|
|
349
|
+
blockLoader: createBlockLoader(rpc),
|
|
337
350
|
cache,
|
|
338
|
-
loadBlock(args, info) {
|
|
339
|
-
return loadBlock(args, this.cache, this.rpc);
|
|
340
|
-
},
|
|
341
351
|
loadProgramAccounts(args, info) {
|
|
342
352
|
return loadProgramAccounts(args, this.cache, this.rpc);
|
|
343
353
|
},
|
|
@@ -2987,7 +2997,7 @@ var schemaResolvers = {
|
|
|
2987
2997
|
return context.accountLoader.load(args, info);
|
|
2988
2998
|
},
|
|
2989
2999
|
block(_, args, context, info) {
|
|
2990
|
-
return context.
|
|
3000
|
+
return context.blockLoader.load(args, info);
|
|
2991
3001
|
},
|
|
2992
3002
|
programAccounts(_, args, context, info) {
|
|
2993
3003
|
return context.loadProgramAccounts(args, info);
|