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