@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.js
CHANGED
|
@@ -214,12 +214,13 @@ async function loadTransaction({ signature, ...config }, cache, rpc, _info) {
|
|
|
214
214
|
|
|
215
215
|
// src/loaders/block.ts
|
|
216
216
|
function normalizeArgs3(args) {
|
|
217
|
-
const { commitment, encoding, transactionDetails } = args;
|
|
217
|
+
const { commitment, encoding, slot, transactionDetails } = args;
|
|
218
218
|
return {
|
|
219
219
|
commitment: commitment ?? "confirmed",
|
|
220
220
|
encoding: encoding ?? "jsonParsed",
|
|
221
221
|
// Always use 0 to avoid silly errors
|
|
222
222
|
maxSupportedTransactionVersion: 0,
|
|
223
|
+
slot,
|
|
223
224
|
transactionDetails: transactionDetails ?? "full"
|
|
224
225
|
};
|
|
225
226
|
}
|
|
@@ -254,23 +255,34 @@ function processQueryResponse3({
|
|
|
254
255
|
transactionDetails
|
|
255
256
|
};
|
|
256
257
|
}
|
|
257
|
-
async function loadBlock({ slot, ...config }
|
|
258
|
-
const
|
|
259
|
-
const
|
|
260
|
-
const cached = cache.get(slot, config);
|
|
261
|
-
if (cached !== null) {
|
|
262
|
-
return cached;
|
|
263
|
-
}
|
|
264
|
-
const block = await rpc.getBlock(slot, requestConfig).send().catch((e) => {
|
|
258
|
+
async function loadBlock(rpc, { slot, ...config }) {
|
|
259
|
+
const { encoding, transactionDetails } = config;
|
|
260
|
+
const block = await rpc.getBlock(slot, config).send().catch((e) => {
|
|
265
261
|
throw e;
|
|
266
262
|
});
|
|
267
263
|
if (block === null) {
|
|
268
264
|
return { slot };
|
|
269
265
|
}
|
|
270
266
|
const queryResponse = processQueryResponse3({ block, encoding, transactionDetails });
|
|
271
|
-
cache.insert(slot, requestConfig, queryResponse);
|
|
272
267
|
return queryResponse;
|
|
273
268
|
}
|
|
269
|
+
function createBlockBatchLoadFn(rpc) {
|
|
270
|
+
const resolveBlockUsingRpc = loadBlock.bind(null, rpc);
|
|
271
|
+
return async (blockQueryArgs) => {
|
|
272
|
+
return await Promise.all(blockQueryArgs.map(async (args) => await resolveBlockUsingRpc(args)));
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function createBlockLoader(rpc) {
|
|
276
|
+
const loader = new DataLoader(createBlockBatchLoadFn(rpc), { cacheKeyFn: fastStableStringify });
|
|
277
|
+
return {
|
|
278
|
+
load: async (args, info) => {
|
|
279
|
+
if (onlyPresentFieldRequested("slot", info)) {
|
|
280
|
+
return { slot: args.slot };
|
|
281
|
+
}
|
|
282
|
+
return loader.load(normalizeArgs3(args));
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
274
286
|
|
|
275
287
|
// src/loaders/program-accounts.ts
|
|
276
288
|
function normalizeArgs4(args) {
|
|
@@ -327,10 +339,8 @@ function createSolanaGraphQLContext(rpc) {
|
|
|
327
339
|
const cache = createGraphQLCache();
|
|
328
340
|
return {
|
|
329
341
|
accountLoader: createAccountLoader(rpc),
|
|
342
|
+
blockLoader: createBlockLoader(rpc),
|
|
330
343
|
cache,
|
|
331
|
-
loadBlock(args, info) {
|
|
332
|
-
return loadBlock(args, this.cache, this.rpc);
|
|
333
|
-
},
|
|
334
344
|
loadProgramAccounts(args, info) {
|
|
335
345
|
return loadProgramAccounts(args, this.cache, this.rpc);
|
|
336
346
|
},
|
|
@@ -2980,7 +2990,7 @@ var schemaResolvers = {
|
|
|
2980
2990
|
return context.accountLoader.load(args, info);
|
|
2981
2991
|
},
|
|
2982
2992
|
block(_, args, context, info) {
|
|
2983
|
-
return context.
|
|
2993
|
+
return context.blockLoader.load(args, info);
|
|
2984
2994
|
},
|
|
2985
2995
|
programAccounts(_, args, context, info) {
|
|
2986
2996
|
return context.loadProgramAccounts(args, info);
|