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