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