@solana/rpc-graphql 2.0.0-experimental.f8c941c → 2.0.0-experimental.fb51adb
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 +619 -333
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +620 -334
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +620 -334
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +619 -333
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +620 -334
- package/dist/index.node.js.map +1 -1
- package/dist/types/context.d.ts +15 -4
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/loaders/account.d.ts +7 -3
- package/dist/types/loaders/account.d.ts.map +1 -1
- package/dist/types/loaders/block.d.ts +1 -2
- package/dist/types/loaders/block.d.ts.map +1 -1
- package/dist/types/loaders/index.d.ts +1 -1
- package/dist/types/loaders/index.d.ts.map +1 -1
- package/dist/types/loaders/loader.d.ts +19 -6
- package/dist/types/loaders/loader.d.ts.map +1 -1
- package/dist/types/loaders/program-accounts.d.ts +1 -2
- package/dist/types/loaders/program-accounts.d.ts.map +1 -1
- package/dist/types/loaders/transaction.d.ts +1 -2
- package/dist/types/loaders/transaction.d.ts.map +1 -1
- package/dist/types/resolvers/account.d.ts +160 -42
- package/dist/types/resolvers/account.d.ts.map +1 -1
- package/dist/types/resolvers/block.d.ts +1 -1
- package/dist/types/resolvers/block.d.ts.map +1 -1
- package/dist/types/resolvers/index.d.ts.map +1 -1
- package/dist/types/resolvers/instruction.d.ts +1275 -255
- package/dist/types/resolvers/instruction.d.ts.map +1 -1
- package/dist/types/resolvers/program-accounts.d.ts +2 -1
- package/dist/types/resolvers/program-accounts.d.ts.map +1 -1
- package/dist/types/resolvers/resolve-info/account.d.ts +14 -0
- package/dist/types/resolvers/resolve-info/account.d.ts.map +1 -0
- package/dist/types/resolvers/resolve-info/index.d.ts +3 -0
- package/dist/types/resolvers/resolve-info/index.d.ts.map +1 -0
- package/dist/types/resolvers/resolve-info/visitor.d.ts +18 -0
- package/dist/types/resolvers/resolve-info/visitor.d.ts.map +1 -0
- package/dist/types/resolvers/transaction.d.ts +1 -1
- package/dist/types/resolvers/transaction.d.ts.map +1 -1
- package/dist/types/resolvers/types.d.ts +79 -4
- package/dist/types/resolvers/types.d.ts.map +1 -1
- package/dist/types/schema/account.d.ts +1 -1
- package/dist/types/schema/account.d.ts.map +1 -1
- package/dist/types/schema/index.d.ts.map +1 -1
- package/dist/types/schema/root.d.ts +1 -1
- package/dist/types/schema/root.d.ts.map +1 -1
- package/dist/types/schema/types.d.ts +2 -0
- package/dist/types/schema/types.d.ts.map +1 -0
- package/package.json +11 -38
- package/dist/types/resolvers/resolve-info.d.ts +0 -3
- package/dist/types/resolvers/resolve-info.d.ts.map +0 -1
- package/dist/types/resolvers/scalars.d.ts +0 -44
- package/dist/types/resolvers/scalars.d.ts.map +0 -1
- package/dist/types/schema/common/inputs.d.ts +0 -2
- package/dist/types/schema/common/inputs.d.ts.map +0 -1
- package/dist/types/schema/common/scalars.d.ts +0 -2
- package/dist/types/schema/common/scalars.d.ts.map +0 -1
- package/dist/types/schema/common/types.d.ts +0 -2
- package/dist/types/schema/common/types.d.ts.map +0 -1
package/dist/index.browser.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var schema = require('@graphql-tools/schema');
|
|
4
4
|
var graphql = require('graphql');
|
|
5
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
5
6
|
var DataLoader = require('dataloader');
|
|
6
7
|
var stringify = require('json-stable-stringify');
|
|
7
8
|
|
|
@@ -20,39 +21,217 @@ function replacer(_, value) {
|
|
|
20
21
|
var cacheKeyFn = (obj) => stringify__default.default(obj, { replacer });
|
|
21
22
|
|
|
22
23
|
// src/loaders/account.ts
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
encoding
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
function getCodec(encoding) {
|
|
25
|
+
switch (encoding) {
|
|
26
|
+
case "base58":
|
|
27
|
+
return codecsStrings.getBase58Codec();
|
|
28
|
+
default:
|
|
29
|
+
return codecsStrings.getBase64Codec();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function sliceData(account, dataSlice, masterDataSlice) {
|
|
33
|
+
if (dataSlice) {
|
|
34
|
+
const masterOffset = masterDataSlice ? masterDataSlice.offset : 0;
|
|
35
|
+
const slicedData = (data, encoding) => {
|
|
36
|
+
if (encoding === "base64+zstd") {
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
const { offset, length } = dataSlice;
|
|
40
|
+
const trueOffset = offset - masterOffset;
|
|
41
|
+
const codec = getCodec(encoding);
|
|
42
|
+
return codec.decode(codec.encode(data).slice(trueOffset, trueOffset + length));
|
|
43
|
+
};
|
|
44
|
+
if (Array.isArray(account.data)) {
|
|
45
|
+
const [data, encoding] = account.data;
|
|
46
|
+
return {
|
|
47
|
+
...account,
|
|
48
|
+
data: [slicedData(data, encoding), encoding]
|
|
49
|
+
};
|
|
50
|
+
} else if (typeof account.data === "string") {
|
|
51
|
+
const data = account.data;
|
|
52
|
+
return {
|
|
53
|
+
...account,
|
|
54
|
+
data: slicedData(data, "base58")
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return account;
|
|
37
59
|
}
|
|
38
60
|
async function loadAccount(rpc, { address, ...config }) {
|
|
39
61
|
return await rpc.getAccountInfo(address, config).send().then((res) => res.value);
|
|
40
62
|
}
|
|
41
|
-
function
|
|
63
|
+
async function loadMultipleAccounts(rpc, { addresses, ...config }) {
|
|
64
|
+
return await rpc.getMultipleAccounts(addresses, config).send().then((res) => res.value);
|
|
65
|
+
}
|
|
66
|
+
var hashOmit = (args, omit) => {
|
|
67
|
+
const argsObj = {};
|
|
68
|
+
for (const [key, value] of Object.entries(args)) {
|
|
69
|
+
if (!omit.includes(key)) {
|
|
70
|
+
argsObj[key] = value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return cacheKeyFn(argsObj);
|
|
74
|
+
};
|
|
75
|
+
function createAccountBatchLoadFn(rpc, config) {
|
|
42
76
|
const resolveAccountUsingRpc = loadAccount.bind(null, rpc);
|
|
77
|
+
const resolveMultipleAccountsUsingRpc = loadMultipleAccounts.bind(null, rpc);
|
|
43
78
|
return async (accountQueryArgs) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
79
|
+
const accountsToFetch = {};
|
|
80
|
+
try {
|
|
81
|
+
return Promise.all(
|
|
82
|
+
accountQueryArgs.map(
|
|
83
|
+
({ address, ...args }) => new Promise((resolve, reject) => {
|
|
84
|
+
const accountRecords = accountsToFetch[address] ||= [];
|
|
85
|
+
if (!args.commitment) {
|
|
86
|
+
args.commitment = "confirmed";
|
|
87
|
+
}
|
|
88
|
+
accountRecords.push({ args, promiseCallback: { reject, resolve } });
|
|
89
|
+
})
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
} finally {
|
|
93
|
+
const { maxDataSliceByteRange, maxMultipleAccountsBatchSize } = config;
|
|
94
|
+
const accountFetchesByArgsHash = {};
|
|
95
|
+
const orphanedFetches = {};
|
|
96
|
+
Object.entries(accountsToFetch).forEach(([address, toFetch]) => {
|
|
97
|
+
toFetch.forEach(({ args, promiseCallback }) => {
|
|
98
|
+
if (!args.encoding) {
|
|
99
|
+
const toFetch2 = orphanedFetches[address] ||= [];
|
|
100
|
+
toFetch2.push({ args, promiseCallback });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (args.encoding != "base64+zstd" && args.dataSlice) {
|
|
104
|
+
const r = args.dataSlice;
|
|
105
|
+
for (const { addresses: fetchAddresses, args: fetchArgs } of Object.values(
|
|
106
|
+
accountFetchesByArgsHash
|
|
107
|
+
)) {
|
|
108
|
+
const addCallbackWithDataSlice = (updateDataSlice) => {
|
|
109
|
+
const { callbacks: promiseCallbacksForAddress2 } = fetchAddresses[address] ||= {
|
|
110
|
+
callbacks: []
|
|
111
|
+
};
|
|
112
|
+
promiseCallbacksForAddress2.push({
|
|
113
|
+
callback: promiseCallback,
|
|
114
|
+
dataSlice: args.dataSlice ?? null
|
|
115
|
+
});
|
|
116
|
+
if (fetchArgs.dataSlice && updateDataSlice) {
|
|
117
|
+
fetchArgs.dataSlice = updateDataSlice;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
if (hashOmit(args, ["dataSlice"]) === hashOmit(fetchArgs, ["dataSlice"])) {
|
|
121
|
+
if (fetchArgs.dataSlice) {
|
|
122
|
+
const g = fetchArgs.dataSlice;
|
|
123
|
+
if (r.offset <= g.offset && g.offset - r.offset + r.length <= maxDataSliceByteRange) {
|
|
124
|
+
const length = Math.max(r.length, g.offset + g.length - r.offset);
|
|
125
|
+
const offset = r.offset;
|
|
126
|
+
addCallbackWithDataSlice({ length, offset });
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (r.offset >= g.offset && r.offset - g.offset + g.length <= maxDataSliceByteRange) {
|
|
130
|
+
const length = Math.max(g.length, r.offset + r.length - g.offset);
|
|
131
|
+
const offset = g.offset;
|
|
132
|
+
addCallbackWithDataSlice({ length, offset });
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
const { length, offset } = r;
|
|
137
|
+
addCallbackWithDataSlice({ length, offset });
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const argsHash = hashOmit(args, []);
|
|
144
|
+
const accountFetches = accountFetchesByArgsHash[argsHash] ||= {
|
|
145
|
+
addresses: {},
|
|
146
|
+
args
|
|
147
|
+
};
|
|
148
|
+
const { callbacks: promiseCallbacksForAddress } = accountFetches.addresses[address] ||= {
|
|
149
|
+
callbacks: []
|
|
150
|
+
};
|
|
151
|
+
promiseCallbacksForAddress.push({ callback: promiseCallback, dataSlice: args.dataSlice ?? null });
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
Object.entries(orphanedFetches).forEach(([address, toFetch]) => {
|
|
155
|
+
toFetch.forEach(({ args: orphanedArgs, promiseCallback: orphanPromiseCallback }) => {
|
|
156
|
+
if (Object.keys(accountFetchesByArgsHash).length !== 0) {
|
|
157
|
+
for (const { addresses, args: args2 } of Object.values(accountFetchesByArgsHash)) {
|
|
158
|
+
if (hashOmit(orphanedArgs, ["encoding", "dataSlice"]) === hashOmit(args2, ["encoding", "dataSlice"])) {
|
|
159
|
+
const { callbacks: promiseCallbacksForAddress2 } = addresses[address] ||= {
|
|
160
|
+
callbacks: []
|
|
161
|
+
};
|
|
162
|
+
promiseCallbacksForAddress2.push({ callback: orphanPromiseCallback });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const args = { ...orphanedArgs, encoding: "base64" };
|
|
168
|
+
const argsHash = hashOmit(args, []);
|
|
169
|
+
const accountFetches = accountFetchesByArgsHash[argsHash] ||= {
|
|
170
|
+
addresses: {},
|
|
171
|
+
args
|
|
172
|
+
};
|
|
173
|
+
const { callbacks: promiseCallbacksForAddress } = accountFetches.addresses[address] ||= {
|
|
174
|
+
callbacks: []
|
|
175
|
+
};
|
|
176
|
+
promiseCallbacksForAddress.push({ callback: orphanPromiseCallback });
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
Object.values(accountFetchesByArgsHash).map(({ args, addresses: addressCallbacks }) => {
|
|
180
|
+
const addresses = Object.keys(addressCallbacks);
|
|
181
|
+
if (addresses.length === 1) {
|
|
182
|
+
const address = addresses[0];
|
|
183
|
+
return Array.from({ length: 1 }, async () => {
|
|
184
|
+
try {
|
|
185
|
+
const result = await resolveAccountUsingRpc({ address, ...args });
|
|
186
|
+
addressCallbacks[address].callbacks.forEach(({ callback, dataSlice }) => {
|
|
187
|
+
callback.resolve(sliceData(result, dataSlice, args.dataSlice));
|
|
188
|
+
});
|
|
189
|
+
} catch (e) {
|
|
190
|
+
addressCallbacks[address].callbacks.forEach(({ callback }) => {
|
|
191
|
+
callback.reject(e);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
} else {
|
|
196
|
+
return Array.from(
|
|
197
|
+
{ length: Math.ceil(addresses.length / maxMultipleAccountsBatchSize) },
|
|
198
|
+
async (_, ii) => {
|
|
199
|
+
const startIndex = ii * maxMultipleAccountsBatchSize;
|
|
200
|
+
const endIndex = startIndex + maxMultipleAccountsBatchSize;
|
|
201
|
+
const chunk = addresses.slice(startIndex, endIndex);
|
|
202
|
+
try {
|
|
203
|
+
const results = await resolveMultipleAccountsUsingRpc({
|
|
204
|
+
addresses: chunk,
|
|
205
|
+
...args
|
|
206
|
+
});
|
|
207
|
+
chunk.forEach((address, ii2) => {
|
|
208
|
+
const result = results[ii2];
|
|
209
|
+
addressCallbacks[address].callbacks.forEach(({ callback, dataSlice }) => {
|
|
210
|
+
callback.resolve(sliceData(result, dataSlice, args.dataSlice));
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
} catch (e) {
|
|
214
|
+
chunk.forEach((address) => {
|
|
215
|
+
addressCallbacks[address].callbacks.forEach(({ callback }) => {
|
|
216
|
+
callback.reject(e);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
47
225
|
};
|
|
48
226
|
}
|
|
49
|
-
function createAccountLoader(rpc) {
|
|
50
|
-
const loader = new DataLoader__default.default(createAccountBatchLoadFn(rpc), { cacheKeyFn });
|
|
227
|
+
function createAccountLoader(rpc, config) {
|
|
228
|
+
const loader = new DataLoader__default.default(createAccountBatchLoadFn(rpc, config), { cacheKeyFn });
|
|
51
229
|
return {
|
|
52
|
-
load: async (args) => loader.load(
|
|
230
|
+
load: async (args) => loader.load(args),
|
|
231
|
+
loadMany: async (args) => loader.loadMany(args)
|
|
53
232
|
};
|
|
54
233
|
}
|
|
55
|
-
function
|
|
234
|
+
function applyDefaultArgs({
|
|
56
235
|
slot,
|
|
57
236
|
commitment,
|
|
58
237
|
encoding = "jsonParsed",
|
|
@@ -72,23 +251,22 @@ function applyDefaultArgs2({
|
|
|
72
251
|
async function loadBlock(rpc, { slot, ...config }) {
|
|
73
252
|
return await rpc.getBlock(
|
|
74
253
|
slot,
|
|
75
|
-
// @ts-expect-error FIX ME: https://github.com/
|
|
254
|
+
// @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
|
|
76
255
|
config
|
|
77
256
|
).send();
|
|
78
257
|
}
|
|
79
258
|
function createBlockBatchLoadFn(rpc) {
|
|
80
259
|
const resolveBlockUsingRpc = loadBlock.bind(null, rpc);
|
|
81
|
-
return async (blockQueryArgs) =>
|
|
82
|
-
return await Promise.all(blockQueryArgs.map(async (args) => await resolveBlockUsingRpc(applyDefaultArgs2(args))));
|
|
83
|
-
};
|
|
260
|
+
return async (blockQueryArgs) => Promise.all(blockQueryArgs.map(async (args) => resolveBlockUsingRpc(applyDefaultArgs(args))));
|
|
84
261
|
}
|
|
85
262
|
function createBlockLoader(rpc) {
|
|
86
263
|
const loader = new DataLoader__default.default(createBlockBatchLoadFn(rpc), { cacheKeyFn });
|
|
87
264
|
return {
|
|
88
|
-
load: async (args) => loader.load(
|
|
265
|
+
load: async (args) => loader.load(applyDefaultArgs(args)),
|
|
266
|
+
loadMany: async (args) => loader.loadMany(args.map(applyDefaultArgs))
|
|
89
267
|
};
|
|
90
268
|
}
|
|
91
|
-
function
|
|
269
|
+
function applyDefaultArgs2({
|
|
92
270
|
commitment,
|
|
93
271
|
dataSlice,
|
|
94
272
|
encoding = "jsonParsed",
|
|
@@ -108,25 +286,22 @@ function applyDefaultArgs3({
|
|
|
108
286
|
async function loadProgramAccounts(rpc, { programAddress, ...config }) {
|
|
109
287
|
return await rpc.getProgramAccounts(
|
|
110
288
|
programAddress,
|
|
111
|
-
// @ts-expect-error FIX ME: https://github.com/
|
|
289
|
+
// @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
|
|
112
290
|
config
|
|
113
291
|
).send();
|
|
114
292
|
}
|
|
115
293
|
function createProgramAccountsBatchLoadFn(rpc) {
|
|
116
294
|
const resolveProgramAccountsUsingRpc = loadProgramAccounts.bind(null, rpc);
|
|
117
|
-
return async (programAccountsQueryArgs) =>
|
|
118
|
-
return await Promise.all(
|
|
119
|
-
programAccountsQueryArgs.map(async (args) => await resolveProgramAccountsUsingRpc(applyDefaultArgs3(args)))
|
|
120
|
-
);
|
|
121
|
-
};
|
|
295
|
+
return async (programAccountsQueryArgs) => Promise.all(programAccountsQueryArgs.map(async (args) => resolveProgramAccountsUsingRpc(applyDefaultArgs2(args))));
|
|
122
296
|
}
|
|
123
297
|
function createProgramAccountsLoader(rpc) {
|
|
124
298
|
const loader = new DataLoader__default.default(createProgramAccountsBatchLoadFn(rpc), { cacheKeyFn });
|
|
125
299
|
return {
|
|
126
|
-
load: async (args) => loader.load(
|
|
300
|
+
load: async (args) => loader.load(applyDefaultArgs2(args)),
|
|
301
|
+
loadMany: async (args) => loader.loadMany(args.map(applyDefaultArgs2))
|
|
127
302
|
};
|
|
128
303
|
}
|
|
129
|
-
function
|
|
304
|
+
function applyDefaultArgs3({
|
|
130
305
|
commitment,
|
|
131
306
|
encoding = "jsonParsed",
|
|
132
307
|
signature
|
|
@@ -140,171 +315,272 @@ function applyDefaultArgs4({
|
|
|
140
315
|
async function loadTransaction(rpc, { signature, ...config }) {
|
|
141
316
|
return await rpc.getTransaction(
|
|
142
317
|
signature,
|
|
143
|
-
// @ts-expect-error FIX ME: https://github.com/
|
|
318
|
+
// @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
|
|
144
319
|
config
|
|
145
320
|
).send();
|
|
146
321
|
}
|
|
147
322
|
function createTransactionBatchLoadFn(rpc) {
|
|
148
323
|
const resolveTransactionUsingRpc = loadTransaction.bind(null, rpc);
|
|
149
|
-
return async (transactionQueryArgs) =>
|
|
150
|
-
return await Promise.all(
|
|
151
|
-
transactionQueryArgs.map(async (args) => await resolveTransactionUsingRpc(applyDefaultArgs4(args)))
|
|
152
|
-
);
|
|
153
|
-
};
|
|
324
|
+
return async (transactionQueryArgs) => Promise.all(transactionQueryArgs.map(async (args) => resolveTransactionUsingRpc(applyDefaultArgs3(args))));
|
|
154
325
|
}
|
|
155
326
|
function createTransactionLoader(rpc) {
|
|
156
327
|
const loader = new DataLoader__default.default(createTransactionBatchLoadFn(rpc), { cacheKeyFn });
|
|
157
328
|
return {
|
|
158
|
-
load: async (args) => loader.load(
|
|
329
|
+
load: async (args) => loader.load(applyDefaultArgs3(args)),
|
|
330
|
+
loadMany: async (args) => loader.loadMany(args.map(applyDefaultArgs3))
|
|
159
331
|
};
|
|
160
332
|
}
|
|
161
333
|
|
|
162
334
|
// src/context.ts
|
|
163
|
-
function createSolanaGraphQLContext(rpc) {
|
|
335
|
+
function createSolanaGraphQLContext(rpc, config) {
|
|
164
336
|
return {
|
|
165
337
|
loaders: {
|
|
166
|
-
account: createAccountLoader(rpc),
|
|
338
|
+
account: createAccountLoader(rpc, config),
|
|
167
339
|
block: createBlockLoader(rpc),
|
|
168
340
|
programAccounts: createProgramAccountsLoader(rpc),
|
|
169
341
|
transaction: createTransactionLoader(rpc)
|
|
170
|
-
}
|
|
171
|
-
rpc
|
|
342
|
+
}
|
|
172
343
|
};
|
|
173
344
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
return
|
|
345
|
+
function injectableRootVisitor(info, rootNode, operations) {
|
|
346
|
+
const { fieldNodes } = info;
|
|
347
|
+
const root = rootNode ?? fieldNodes[0];
|
|
348
|
+
const parentIsRoot = (ancestors) => (Array.isArray(ancestors) ? ancestors[0] : ancestors) === root;
|
|
349
|
+
graphql.visit(root, {
|
|
350
|
+
Field(node, key, parent, path, ancestors) {
|
|
351
|
+
if (!parentIsRoot(ancestors))
|
|
352
|
+
return;
|
|
353
|
+
return operations.fieldNodeOperation(info, node, key, parent, path, ancestors);
|
|
354
|
+
},
|
|
355
|
+
FragmentSpread(node, key, parent, path, ancestors) {
|
|
356
|
+
const fragmentDefinition = info.fragments[node.name.value];
|
|
357
|
+
return operations.fragmentSpreadNodeOperation(info, fragmentDefinition, node, key, parent, path, ancestors);
|
|
358
|
+
},
|
|
359
|
+
InlineFragment(node, key, parent, path, ancestors) {
|
|
360
|
+
if (!parentIsRoot(ancestors))
|
|
361
|
+
return;
|
|
362
|
+
return operations.inlineFragmentNodeOperation(info, node, key, parent, path, ancestors);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
function onlyFieldsRequested(fieldNames, info, rootNode) {
|
|
367
|
+
let onlyFieldsRequested2 = true;
|
|
368
|
+
function checkFieldsWithVisitor(root) {
|
|
369
|
+
injectableRootVisitor(info, root, {
|
|
370
|
+
fieldNodeOperation(_info, node) {
|
|
371
|
+
onlyFieldsRequested2 = fieldNames.includes(node.name.value);
|
|
372
|
+
if (!onlyFieldsRequested2) {
|
|
373
|
+
return graphql.BREAK;
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
fragmentSpreadNodeOperation(_info, fragment) {
|
|
377
|
+
checkFieldsWithVisitor(fragment);
|
|
378
|
+
},
|
|
379
|
+
inlineFragmentNodeOperation(_info, node) {
|
|
380
|
+
checkFieldsWithVisitor(node);
|
|
182
381
|
}
|
|
183
|
-
return null;
|
|
184
382
|
});
|
|
185
|
-
|
|
186
|
-
|
|
383
|
+
}
|
|
384
|
+
checkFieldsWithVisitor(rootNode ?? null);
|
|
385
|
+
return onlyFieldsRequested2;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/resolvers/resolve-info/account.ts
|
|
389
|
+
function findArgumentNodeByName(argumentNodes, name) {
|
|
390
|
+
return argumentNodes.find((argumentNode) => argumentNode.name.value === name);
|
|
391
|
+
}
|
|
392
|
+
function parseAccountEncodingArgument(argumentNodes, variableValues) {
|
|
393
|
+
const argumentNode = findArgumentNodeByName(argumentNodes, "encoding");
|
|
394
|
+
if (argumentNode) {
|
|
395
|
+
if (argumentNode.value.kind === "EnumValue") {
|
|
396
|
+
if (argumentNode.value.value === "BASE_58") {
|
|
397
|
+
return "base58";
|
|
398
|
+
}
|
|
399
|
+
if (argumentNode.value.value === "BASE_64") {
|
|
400
|
+
return "base64";
|
|
401
|
+
}
|
|
402
|
+
if (argumentNode.value.value === "BASE_64_ZSTD") {
|
|
403
|
+
return "base64+zstd";
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (argumentNode.value.kind === "Variable") {
|
|
407
|
+
return variableValues[argumentNode.value.name.value];
|
|
187
408
|
}
|
|
409
|
+
} else {
|
|
410
|
+
return void 0;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function parseAccountDataSliceArgument(argumentNodes, variableValues) {
|
|
414
|
+
const argumentNode = findArgumentNodeByName(argumentNodes, "dataSlice");
|
|
415
|
+
if (argumentNode) {
|
|
416
|
+
if (argumentNode.value.kind === "ObjectValue") {
|
|
417
|
+
const offsetArg = argumentNode.value.fields?.find((field) => field.name.value === "offset");
|
|
418
|
+
const lengthArg = argumentNode.value.fields?.find((field) => field.name.value === "length");
|
|
419
|
+
const length = lengthArg?.value.kind === "IntValue" ? parseInt(lengthArg.value.value) : lengthArg?.value.kind === "Variable" ? variableValues[lengthArg.value.name.value] : void 0;
|
|
420
|
+
const offset = offsetArg?.value.kind === "IntValue" ? parseInt(offsetArg.value.value) : offsetArg?.value.kind === "Variable" ? variableValues[offsetArg.value.name.value] : void 0;
|
|
421
|
+
return length !== void 0 && length !== null && offset !== void 0 && offset !== null ? { length, offset } : void 0;
|
|
422
|
+
}
|
|
423
|
+
if (argumentNode.value.kind === "Variable") {
|
|
424
|
+
return variableValues[argumentNode.value.name.value];
|
|
425
|
+
}
|
|
426
|
+
} else {
|
|
427
|
+
return void 0;
|
|
188
428
|
}
|
|
189
|
-
|
|
429
|
+
}
|
|
430
|
+
function buildAccountLoaderArgSetFromResolveInfo(args, info) {
|
|
431
|
+
const argSet = [args];
|
|
432
|
+
function buildArgSetWithVisitor(root) {
|
|
433
|
+
injectableRootVisitor(info, root, {
|
|
434
|
+
fieldNodeOperation(info2, node) {
|
|
435
|
+
if (node.name.value !== "data") {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
if (node.arguments) {
|
|
439
|
+
const { variableValues } = info2;
|
|
440
|
+
const encoding = parseAccountEncodingArgument(node.arguments, variableValues);
|
|
441
|
+
const dataSlice = parseAccountDataSliceArgument(node.arguments, variableValues);
|
|
442
|
+
argSet.push({ ...args, dataSlice, encoding });
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
fragmentSpreadNodeOperation(_info, fragment) {
|
|
446
|
+
buildArgSetWithVisitor(fragment);
|
|
447
|
+
},
|
|
448
|
+
inlineFragmentNodeOperation(info2, node) {
|
|
449
|
+
const { schema } = info2;
|
|
450
|
+
const accountInterface = schema.getType("Account");
|
|
451
|
+
if (graphql.isInterfaceType(accountInterface) && // Recursively check if the inline fragment requests any
|
|
452
|
+
// fields outside of the `Account` interface.
|
|
453
|
+
!onlyFieldsRequested(Object.keys(accountInterface.getFields()), info2, node)) {
|
|
454
|
+
argSet.push({ ...args, encoding: "jsonParsed" });
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
buildArgSetWithVisitor(null);
|
|
460
|
+
return argSet;
|
|
190
461
|
}
|
|
191
462
|
|
|
192
463
|
// src/resolvers/account.ts
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
program: programName,
|
|
197
|
-
programId
|
|
198
|
-
} = parsedAccountData;
|
|
199
|
-
result.accountType = accountType;
|
|
200
|
-
result.programId = programId;
|
|
201
|
-
result.programName = programName;
|
|
202
|
-
return result;
|
|
203
|
-
}
|
|
204
|
-
function transformLoadedAccount({
|
|
205
|
-
account,
|
|
206
|
-
address,
|
|
207
|
-
encoding = "jsonParsed"
|
|
208
|
-
}) {
|
|
209
|
-
const [
|
|
210
|
-
// The account's data, either encoded or parsed.
|
|
211
|
-
data,
|
|
212
|
-
// Tells GraphQL which encoding has been returned
|
|
213
|
-
// by the RPC.
|
|
214
|
-
responseEncoding
|
|
215
|
-
] = Array.isArray(account.data) ? encoding === "jsonParsed" ? (
|
|
216
|
-
// The requested encoding is jsonParsed,
|
|
217
|
-
// but the data could not be parsed.
|
|
218
|
-
// Defaults to base64 encoding.
|
|
219
|
-
[{ data: account.data[0] }, "base64"]
|
|
220
|
-
) : (
|
|
221
|
-
// The requested encoding is base58,
|
|
222
|
-
// base64, or base64+zstd.
|
|
223
|
-
[{ data: account.data[0] }, encoding]
|
|
224
|
-
) : (
|
|
225
|
-
// The account data was returned as an object,
|
|
226
|
-
// so it was parsed successfully.
|
|
227
|
-
[transformParsedAccountData(account.data), "jsonParsed"]
|
|
228
|
-
);
|
|
229
|
-
account.address = address;
|
|
230
|
-
account.encoding = responseEncoding;
|
|
231
|
-
account.ownerProgram = account.owner;
|
|
232
|
-
return {
|
|
233
|
-
...account,
|
|
234
|
-
...data
|
|
464
|
+
var resolveAccountData = () => {
|
|
465
|
+
return (parent, args) => {
|
|
466
|
+
return parent === null ? null : parent.encodedData ? parent.encodedData[cacheKeyFn(args)] : null;
|
|
235
467
|
};
|
|
236
|
-
}
|
|
468
|
+
};
|
|
237
469
|
var resolveAccount = (fieldName) => {
|
|
238
470
|
return async (parent, args, context, info) => {
|
|
239
471
|
const address = fieldName ? parent[fieldName] : args.address;
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (onlyPresentFieldRequested("address", info)) {
|
|
244
|
-
return { address };
|
|
245
|
-
}
|
|
246
|
-
const account = await context.loaders.account.load({ ...args, address });
|
|
247
|
-
return account === null ? { address } : transformLoadedAccount({ account, address, encoding: args.encoding });
|
|
248
|
-
};
|
|
249
|
-
};
|
|
250
|
-
var accountResolvers = {
|
|
251
|
-
Account: {
|
|
252
|
-
__resolveType(account) {
|
|
253
|
-
if (account.encoding === "base58") {
|
|
254
|
-
return "AccountBase58";
|
|
255
|
-
}
|
|
256
|
-
if (account.encoding === "base64") {
|
|
257
|
-
return "AccountBase64";
|
|
258
|
-
}
|
|
259
|
-
if (account.encoding === "base64+zstd") {
|
|
260
|
-
return "AccountBase64Zstd";
|
|
472
|
+
if (address) {
|
|
473
|
+
if (onlyFieldsRequested(["address"], info)) {
|
|
474
|
+
return { address };
|
|
261
475
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
476
|
+
const argsSet = buildAccountLoaderArgSetFromResolveInfo({ ...args, address }, info);
|
|
477
|
+
const loadedAccounts = await context.loaders.account.loadMany(argsSet);
|
|
478
|
+
let result = {
|
|
479
|
+
address,
|
|
480
|
+
encodedData: {}
|
|
481
|
+
};
|
|
482
|
+
loadedAccounts.forEach((account, i) => {
|
|
483
|
+
if (account instanceof Error) {
|
|
484
|
+
console.error(account);
|
|
485
|
+
return;
|
|
265
486
|
}
|
|
266
|
-
if (account
|
|
267
|
-
return
|
|
487
|
+
if (account === null) {
|
|
488
|
+
return;
|
|
268
489
|
}
|
|
269
|
-
if (
|
|
270
|
-
|
|
490
|
+
if (!result.ownerProgram) {
|
|
491
|
+
result = {
|
|
492
|
+
...result,
|
|
493
|
+
...account,
|
|
494
|
+
ownerProgram: account.owner
|
|
495
|
+
};
|
|
271
496
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
497
|
+
const { data } = account;
|
|
498
|
+
const { encoding, dataSlice } = argsSet[i];
|
|
499
|
+
if (encoding && result.encodedData) {
|
|
500
|
+
if (Array.isArray(data)) {
|
|
501
|
+
result.encodedData[cacheKeyFn({
|
|
502
|
+
dataSlice,
|
|
503
|
+
encoding: encoding === "jsonParsed" ? "base64" : encoding
|
|
504
|
+
})] = data[0];
|
|
505
|
+
} else if (typeof data === "string") {
|
|
506
|
+
result.encodedData[cacheKeyFn({
|
|
507
|
+
dataSlice,
|
|
508
|
+
encoding: "base58"
|
|
509
|
+
})] = data;
|
|
510
|
+
} else if (typeof data === "object") {
|
|
511
|
+
const {
|
|
512
|
+
parsed: { info: parsedData, type: accountType },
|
|
513
|
+
program: programName,
|
|
514
|
+
programId
|
|
515
|
+
} = data;
|
|
516
|
+
result.jsonParsedConfigs = {
|
|
517
|
+
accountType,
|
|
518
|
+
programId,
|
|
519
|
+
programName
|
|
520
|
+
};
|
|
521
|
+
result = {
|
|
522
|
+
...result,
|
|
523
|
+
...parsedData
|
|
524
|
+
};
|
|
525
|
+
}
|
|
280
526
|
}
|
|
281
|
-
}
|
|
282
|
-
return
|
|
527
|
+
});
|
|
528
|
+
return result;
|
|
283
529
|
}
|
|
530
|
+
return null;
|
|
531
|
+
};
|
|
532
|
+
};
|
|
533
|
+
function resolveAccountType(accountResult) {
|
|
534
|
+
const { jsonParsedConfigs } = accountResult;
|
|
535
|
+
if (jsonParsedConfigs) {
|
|
536
|
+
if (jsonParsedConfigs.programName === "nonce") {
|
|
537
|
+
return "NonceAccount";
|
|
538
|
+
}
|
|
539
|
+
if (jsonParsedConfigs.accountType === "mint" && jsonParsedConfigs.programName === "spl-token") {
|
|
540
|
+
return "MintAccount";
|
|
541
|
+
}
|
|
542
|
+
if (jsonParsedConfigs.accountType === "account" && jsonParsedConfigs.programName === "spl-token") {
|
|
543
|
+
return "TokenAccount";
|
|
544
|
+
}
|
|
545
|
+
if (jsonParsedConfigs.programName === "stake") {
|
|
546
|
+
return "StakeAccount";
|
|
547
|
+
}
|
|
548
|
+
if (jsonParsedConfigs.accountType === "vote" && jsonParsedConfigs.programName === "vote") {
|
|
549
|
+
return "VoteAccount";
|
|
550
|
+
}
|
|
551
|
+
if (jsonParsedConfigs.accountType === "lookupTable" && jsonParsedConfigs.programName === "address-lookup-table") {
|
|
552
|
+
return "LookupTableAccount";
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return "GenericAccount";
|
|
556
|
+
}
|
|
557
|
+
var accountResolvers = {
|
|
558
|
+
Account: {
|
|
559
|
+
__resolveType: resolveAccountType,
|
|
560
|
+
data: resolveAccountData()
|
|
284
561
|
},
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
},
|
|
288
|
-
AccountBase64: {
|
|
289
|
-
ownerProgram: resolveAccount("ownerProgram")
|
|
290
|
-
},
|
|
291
|
-
AccountBase64Zstd: {
|
|
562
|
+
GenericAccount: {
|
|
563
|
+
data: resolveAccountData(),
|
|
292
564
|
ownerProgram: resolveAccount("ownerProgram")
|
|
293
565
|
},
|
|
294
566
|
LookupTableAccount: {
|
|
295
567
|
authority: resolveAccount("authority"),
|
|
568
|
+
data: resolveAccountData(),
|
|
296
569
|
ownerProgram: resolveAccount("ownerProgram")
|
|
297
570
|
},
|
|
298
571
|
MintAccount: {
|
|
572
|
+
data: resolveAccountData(),
|
|
299
573
|
freezeAuthority: resolveAccount("freezeAuthority"),
|
|
300
574
|
mintAuthority: resolveAccount("mintAuthority"),
|
|
301
575
|
ownerProgram: resolveAccount("ownerProgram")
|
|
302
576
|
},
|
|
303
577
|
NonceAccount: {
|
|
304
578
|
authority: resolveAccount("authority"),
|
|
579
|
+
data: resolveAccountData(),
|
|
305
580
|
ownerProgram: resolveAccount("ownerProgram")
|
|
306
581
|
},
|
|
307
582
|
StakeAccount: {
|
|
583
|
+
data: resolveAccountData(),
|
|
308
584
|
ownerProgram: resolveAccount("ownerProgram")
|
|
309
585
|
},
|
|
310
586
|
StakeAccountDataMetaAuthorized: {
|
|
@@ -318,12 +594,14 @@ var accountResolvers = {
|
|
|
318
594
|
voter: resolveAccount("voter")
|
|
319
595
|
},
|
|
320
596
|
TokenAccount: {
|
|
597
|
+
data: resolveAccountData(),
|
|
321
598
|
mint: resolveAccount("mint"),
|
|
322
599
|
owner: resolveAccount("owner"),
|
|
323
600
|
ownerProgram: resolveAccount("ownerProgram")
|
|
324
601
|
},
|
|
325
602
|
VoteAccount: {
|
|
326
603
|
authorizedWithdrawer: resolveAccount("authorizedWithdrawer"),
|
|
604
|
+
data: resolveAccountData(),
|
|
327
605
|
node: resolveAccount("nodePubkey"),
|
|
328
606
|
ownerProgram: resolveAccount("ownerProgram")
|
|
329
607
|
},
|
|
@@ -383,7 +661,7 @@ function resolveTransaction(fieldName) {
|
|
|
383
661
|
if (!signature) {
|
|
384
662
|
return null;
|
|
385
663
|
}
|
|
386
|
-
if (
|
|
664
|
+
if (onlyFieldsRequested(["signature"], info)) {
|
|
387
665
|
return { signature };
|
|
388
666
|
}
|
|
389
667
|
const transaction = await context.loaders.transaction.load({ ...args, signature });
|
|
@@ -449,7 +727,7 @@ var resolveBlock = (fieldName) => {
|
|
|
449
727
|
if (!slot) {
|
|
450
728
|
return null;
|
|
451
729
|
}
|
|
452
|
-
if (
|
|
730
|
+
if (onlyFieldsRequested(["slot"], info)) {
|
|
453
731
|
return { slot };
|
|
454
732
|
}
|
|
455
733
|
const block = await context.loaders.block.load({ ...args, slot });
|
|
@@ -1198,20 +1476,55 @@ var instructionResolvers = {
|
|
|
1198
1476
|
function resolveProgramAccounts(fieldName) {
|
|
1199
1477
|
return async (parent, args, context, info) => {
|
|
1200
1478
|
const programAddress = fieldName ? parent[fieldName] : args.programAddress;
|
|
1201
|
-
if (
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
return { programAddress };
|
|
1479
|
+
if (programAddress) {
|
|
1480
|
+
if (onlyFieldsRequested(["programAddress"], info)) {
|
|
1481
|
+
return { programAddress };
|
|
1482
|
+
}
|
|
1206
1483
|
}
|
|
1207
1484
|
const programAccounts = await context.loaders.programAccounts.load({ ...args, programAddress });
|
|
1208
|
-
|
|
1209
|
-
(programAccount) =>
|
|
1210
|
-
account: programAccount
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1485
|
+
if (programAccounts) {
|
|
1486
|
+
return programAccounts.map((programAccount) => {
|
|
1487
|
+
const { account, pubkey: address } = programAccount;
|
|
1488
|
+
let result = {
|
|
1489
|
+
...account,
|
|
1490
|
+
address,
|
|
1491
|
+
encodedData: {},
|
|
1492
|
+
ownerProgram: account.owner
|
|
1493
|
+
};
|
|
1494
|
+
const { data } = account;
|
|
1495
|
+
const { encoding, dataSlice } = args;
|
|
1496
|
+
if (result.encodedData) {
|
|
1497
|
+
if (Array.isArray(data)) {
|
|
1498
|
+
result.encodedData[cacheKeyFn({
|
|
1499
|
+
dataSlice,
|
|
1500
|
+
encoding: encoding === "jsonParsed" ? "base64" : encoding ?? "base64"
|
|
1501
|
+
})] = data[0];
|
|
1502
|
+
} else if (typeof data === "string") {
|
|
1503
|
+
result.encodedData[cacheKeyFn({
|
|
1504
|
+
dataSlice,
|
|
1505
|
+
encoding: "base58"
|
|
1506
|
+
})] = data;
|
|
1507
|
+
} else if (typeof data === "object") {
|
|
1508
|
+
const {
|
|
1509
|
+
parsed: { info: parsedData, type: accountType },
|
|
1510
|
+
program: programName,
|
|
1511
|
+
programId
|
|
1512
|
+
} = data;
|
|
1513
|
+
result.jsonParsedConfigs = {
|
|
1514
|
+
accountType,
|
|
1515
|
+
programId,
|
|
1516
|
+
programName
|
|
1517
|
+
};
|
|
1518
|
+
result = {
|
|
1519
|
+
...result,
|
|
1520
|
+
...parsedData
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
return result;
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
return null;
|
|
1215
1528
|
};
|
|
1216
1529
|
}
|
|
1217
1530
|
|
|
@@ -1238,35 +1551,44 @@ var stringScalarAlias = {
|
|
|
1238
1551
|
return value;
|
|
1239
1552
|
}
|
|
1240
1553
|
};
|
|
1241
|
-
var
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
Base64ZstdEncodedBytes: stringScalarAlias,
|
|
1246
|
-
BigInt: {
|
|
1247
|
-
__parseLiteral(ast) {
|
|
1248
|
-
if (ast.kind === graphql.Kind.STRING) {
|
|
1249
|
-
return BigInt(ast.value);
|
|
1250
|
-
}
|
|
1251
|
-
return null;
|
|
1252
|
-
},
|
|
1253
|
-
__parseValue(value) {
|
|
1254
|
-
return BigInt(value);
|
|
1255
|
-
},
|
|
1256
|
-
__serialize(value) {
|
|
1257
|
-
return BigInt(value);
|
|
1554
|
+
var bigIntScalarAlias = {
|
|
1555
|
+
__parseLiteral(ast) {
|
|
1556
|
+
if (ast.kind === graphql.Kind.STRING) {
|
|
1557
|
+
return BigInt(ast.value);
|
|
1258
1558
|
}
|
|
1559
|
+
return null;
|
|
1560
|
+
},
|
|
1561
|
+
__parseValue(value) {
|
|
1562
|
+
return BigInt(value);
|
|
1563
|
+
},
|
|
1564
|
+
__serialize(value) {
|
|
1565
|
+
return BigInt(value);
|
|
1259
1566
|
}
|
|
1260
1567
|
};
|
|
1261
|
-
|
|
1262
|
-
// src/resolvers/types.ts
|
|
1263
|
-
var commonTypeResolvers = {
|
|
1568
|
+
var typeTypeResolvers = {
|
|
1264
1569
|
AccountEncoding: {
|
|
1265
1570
|
BASE_58: "base58",
|
|
1266
1571
|
BASE_64: "base64",
|
|
1267
|
-
BASE_64_ZSTD: "base64+zstd"
|
|
1268
|
-
PARSED: "jsonParsed"
|
|
1572
|
+
BASE_64_ZSTD: "base64+zstd"
|
|
1269
1573
|
},
|
|
1574
|
+
Address: stringScalarAlias,
|
|
1575
|
+
Base58EncodedBytes: stringScalarAlias,
|
|
1576
|
+
Base64EncodedBytes: stringScalarAlias,
|
|
1577
|
+
Base64ZstdEncodedBytes: stringScalarAlias,
|
|
1578
|
+
BigInt: bigIntScalarAlias,
|
|
1579
|
+
BlockTransactionDetails: {
|
|
1580
|
+
ACCOUNTS: "accounts",
|
|
1581
|
+
FULL: "full",
|
|
1582
|
+
NONE: "none",
|
|
1583
|
+
SIGNATURES: "signatures"
|
|
1584
|
+
},
|
|
1585
|
+
Commitment: {
|
|
1586
|
+
CONFIRMED: "confirmed",
|
|
1587
|
+
FINALIZED: "finalized",
|
|
1588
|
+
PROCESSED: "processed"
|
|
1589
|
+
},
|
|
1590
|
+
Signature: stringScalarAlias,
|
|
1591
|
+
Slot: bigIntScalarAlias,
|
|
1270
1592
|
TokenBalance: {
|
|
1271
1593
|
mint: resolveAccount("mint"),
|
|
1272
1594
|
owner: resolveAccount("owner")
|
|
@@ -1287,11 +1609,10 @@ function createSolanaGraphQLResolvers() {
|
|
|
1287
1609
|
return {
|
|
1288
1610
|
...accountResolvers,
|
|
1289
1611
|
...blockResolvers,
|
|
1290
|
-
...commonTypeResolvers,
|
|
1291
1612
|
...instructionResolvers,
|
|
1292
1613
|
...rootResolvers,
|
|
1293
|
-
...
|
|
1294
|
-
...
|
|
1614
|
+
...transactionResolvers,
|
|
1615
|
+
...typeTypeResolvers
|
|
1295
1616
|
};
|
|
1296
1617
|
}
|
|
1297
1618
|
|
|
@@ -1304,6 +1625,7 @@ var accountTypeDefs = (
|
|
|
1304
1625
|
"""
|
|
1305
1626
|
interface Account {
|
|
1306
1627
|
address: Address
|
|
1628
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1307
1629
|
executable: Boolean
|
|
1308
1630
|
lamports: BigInt
|
|
1309
1631
|
ownerProgram: Account
|
|
@@ -1312,37 +1634,11 @@ var accountTypeDefs = (
|
|
|
1312
1634
|
}
|
|
1313
1635
|
|
|
1314
1636
|
"""
|
|
1315
|
-
|
|
1637
|
+
Generic base account type
|
|
1316
1638
|
"""
|
|
1317
|
-
type
|
|
1639
|
+
type GenericAccount implements Account {
|
|
1318
1640
|
address: Address
|
|
1319
|
-
data:
|
|
1320
|
-
executable: Boolean
|
|
1321
|
-
lamports: BigInt
|
|
1322
|
-
ownerProgram: Account
|
|
1323
|
-
space: BigInt
|
|
1324
|
-
rentEpoch: BigInt
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
"""
|
|
1328
|
-
An account with base64 encoded data
|
|
1329
|
-
"""
|
|
1330
|
-
type AccountBase64 implements Account {
|
|
1331
|
-
address: Address
|
|
1332
|
-
data: Base64EncodedBytes
|
|
1333
|
-
executable: Boolean
|
|
1334
|
-
lamports: BigInt
|
|
1335
|
-
ownerProgram: Account
|
|
1336
|
-
space: BigInt
|
|
1337
|
-
rentEpoch: BigInt
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
"""
|
|
1341
|
-
An account with base64+zstd encoded data
|
|
1342
|
-
"""
|
|
1343
|
-
type AccountBase64Zstd implements Account {
|
|
1344
|
-
address: Address
|
|
1345
|
-
data: Base64ZstdEncodedBytes
|
|
1641
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1346
1642
|
executable: Boolean
|
|
1347
1643
|
lamports: BigInt
|
|
1348
1644
|
ownerProgram: Account
|
|
@@ -1358,6 +1654,7 @@ var accountTypeDefs = (
|
|
|
1358
1654
|
"""
|
|
1359
1655
|
type NonceAccount implements Account {
|
|
1360
1656
|
address: Address
|
|
1657
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1361
1658
|
executable: Boolean
|
|
1362
1659
|
lamports: BigInt
|
|
1363
1660
|
ownerProgram: Account
|
|
@@ -1373,6 +1670,7 @@ var accountTypeDefs = (
|
|
|
1373
1670
|
"""
|
|
1374
1671
|
type LookupTableAccount implements Account {
|
|
1375
1672
|
address: Address
|
|
1673
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1376
1674
|
executable: Boolean
|
|
1377
1675
|
lamports: BigInt
|
|
1378
1676
|
ownerProgram: Account
|
|
@@ -1390,6 +1688,7 @@ var accountTypeDefs = (
|
|
|
1390
1688
|
"""
|
|
1391
1689
|
type MintAccount implements Account {
|
|
1392
1690
|
address: Address
|
|
1691
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1393
1692
|
executable: Boolean
|
|
1394
1693
|
lamports: BigInt
|
|
1395
1694
|
ownerProgram: Account
|
|
@@ -1407,6 +1706,7 @@ var accountTypeDefs = (
|
|
|
1407
1706
|
"""
|
|
1408
1707
|
type TokenAccount implements Account {
|
|
1409
1708
|
address: Address
|
|
1709
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1410
1710
|
executable: Boolean
|
|
1411
1711
|
lamports: BigInt
|
|
1412
1712
|
ownerProgram: Account
|
|
@@ -1449,6 +1749,7 @@ var accountTypeDefs = (
|
|
|
1449
1749
|
"""
|
|
1450
1750
|
type StakeAccount implements Account {
|
|
1451
1751
|
address: Address
|
|
1752
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1452
1753
|
executable: Boolean
|
|
1453
1754
|
lamports: BigInt
|
|
1454
1755
|
ownerProgram: Account
|
|
@@ -1480,6 +1781,7 @@ var accountTypeDefs = (
|
|
|
1480
1781
|
"""
|
|
1481
1782
|
type VoteAccount implements Account {
|
|
1482
1783
|
address: Address
|
|
1784
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1483
1785
|
executable: Boolean
|
|
1484
1786
|
lamports: BigInt
|
|
1485
1787
|
ownerProgram: Account
|
|
@@ -1593,101 +1895,6 @@ var blockTypeDefs = (
|
|
|
1593
1895
|
`
|
|
1594
1896
|
);
|
|
1595
1897
|
|
|
1596
|
-
// src/schema/common/inputs.ts
|
|
1597
|
-
var inputTypeDefs = (
|
|
1598
|
-
/* GraphQL */
|
|
1599
|
-
`
|
|
1600
|
-
input DataSlice {
|
|
1601
|
-
offset: Int
|
|
1602
|
-
length: Int
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
input ProgramAccountsFilter {
|
|
1606
|
-
bytes: BigInt
|
|
1607
|
-
dataSize: BigInt
|
|
1608
|
-
encoding: AccountEncoding
|
|
1609
|
-
offset: BigInt
|
|
1610
|
-
}
|
|
1611
|
-
`
|
|
1612
|
-
);
|
|
1613
|
-
|
|
1614
|
-
// src/schema/common/scalars.ts
|
|
1615
|
-
var scalarTypeDefs = (
|
|
1616
|
-
/* GraphQL */
|
|
1617
|
-
`
|
|
1618
|
-
scalar Address
|
|
1619
|
-
scalar Base58EncodedBytes
|
|
1620
|
-
scalar Base64EncodedBytes
|
|
1621
|
-
scalar Base64ZstdEncodedBytes
|
|
1622
|
-
scalar BigInt
|
|
1623
|
-
`
|
|
1624
|
-
);
|
|
1625
|
-
|
|
1626
|
-
// src/schema/common/types.ts
|
|
1627
|
-
var commonTypeDefs = (
|
|
1628
|
-
/* GraphQL */
|
|
1629
|
-
`
|
|
1630
|
-
enum AccountEncoding {
|
|
1631
|
-
BASE_58
|
|
1632
|
-
BASE_64
|
|
1633
|
-
BASE_64_ZSTD
|
|
1634
|
-
PARSED
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
enum BlockTransactionDetails {
|
|
1638
|
-
accounts
|
|
1639
|
-
full
|
|
1640
|
-
none
|
|
1641
|
-
signatures
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
enum Commitment {
|
|
1645
|
-
confirmed
|
|
1646
|
-
finalized
|
|
1647
|
-
processed
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
|
-
type ReturnData {
|
|
1651
|
-
data: Base64EncodedBytes
|
|
1652
|
-
programId: Address
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
type Reward {
|
|
1656
|
-
commission: Int
|
|
1657
|
-
lamports: BigInt
|
|
1658
|
-
postBalance: BigInt
|
|
1659
|
-
pubkey: Address
|
|
1660
|
-
rewardType: String
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
type TokenAmount {
|
|
1664
|
-
amount: String
|
|
1665
|
-
decimals: Int
|
|
1666
|
-
uiAmount: BigInt
|
|
1667
|
-
uiAmountString: String
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
|
-
type TokenBalance {
|
|
1671
|
-
accountIndex: Int
|
|
1672
|
-
mint: Account
|
|
1673
|
-
owner: Account
|
|
1674
|
-
programId: Address
|
|
1675
|
-
uiTokenAmount: TokenAmount
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1678
|
-
enum TransactionEncoding {
|
|
1679
|
-
BASE_58
|
|
1680
|
-
BASE_64
|
|
1681
|
-
PARSED
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
enum TransactionVersion {
|
|
1685
|
-
LEGACY
|
|
1686
|
-
ZERO
|
|
1687
|
-
}
|
|
1688
|
-
`
|
|
1689
|
-
);
|
|
1690
|
-
|
|
1691
1898
|
// src/schema/instruction.ts
|
|
1692
1899
|
var instructionTypeDefs = (
|
|
1693
1900
|
/* GraphQL */
|
|
@@ -2741,28 +2948,22 @@ var rootTypeDefs = (
|
|
|
2741
2948
|
/* GraphQL */
|
|
2742
2949
|
`
|
|
2743
2950
|
type Query {
|
|
2744
|
-
account(
|
|
2745
|
-
address: String!
|
|
2746
|
-
commitment: Commitment
|
|
2747
|
-
dataSlice: DataSlice
|
|
2748
|
-
encoding: AccountEncoding
|
|
2749
|
-
minContextSlot: BigInt
|
|
2750
|
-
): Account
|
|
2951
|
+
account(address: Address!, commitment: Commitment, minContextSlot: Slot): Account
|
|
2751
2952
|
block(
|
|
2752
|
-
slot:
|
|
2953
|
+
slot: Slot!
|
|
2753
2954
|
commitment: Commitment
|
|
2754
2955
|
encoding: TransactionEncoding
|
|
2755
2956
|
transactionDetails: BlockTransactionDetails
|
|
2756
2957
|
): Block
|
|
2757
2958
|
programAccounts(
|
|
2758
|
-
programAddress:
|
|
2959
|
+
programAddress: Address!
|
|
2759
2960
|
commitment: Commitment
|
|
2760
2961
|
dataSlice: DataSlice
|
|
2761
2962
|
encoding: AccountEncoding
|
|
2762
2963
|
filters: [ProgramAccountsFilter]
|
|
2763
|
-
minContextSlot:
|
|
2964
|
+
minContextSlot: Slot
|
|
2764
2965
|
): [Account]
|
|
2765
|
-
transaction(signature:
|
|
2966
|
+
transaction(signature: Signature!, commitment: Commitment, encoding: TransactionEncoding): Transaction
|
|
2766
2967
|
}
|
|
2767
2968
|
|
|
2768
2969
|
schema {
|
|
@@ -2885,29 +3086,114 @@ var transactionTypeDefs = (
|
|
|
2885
3086
|
`
|
|
2886
3087
|
);
|
|
2887
3088
|
|
|
3089
|
+
// src/schema/types.ts
|
|
3090
|
+
var typeTypeDefs = (
|
|
3091
|
+
/* GraphQL */
|
|
3092
|
+
`
|
|
3093
|
+
enum AccountEncoding {
|
|
3094
|
+
BASE_58
|
|
3095
|
+
BASE_64
|
|
3096
|
+
BASE_64_ZSTD
|
|
3097
|
+
}
|
|
3098
|
+
|
|
3099
|
+
scalar Address
|
|
3100
|
+
|
|
3101
|
+
scalar Base58EncodedBytes
|
|
3102
|
+
|
|
3103
|
+
scalar Base64EncodedBytes
|
|
3104
|
+
|
|
3105
|
+
scalar Base64ZstdEncodedBytes
|
|
3106
|
+
|
|
3107
|
+
scalar BigInt
|
|
3108
|
+
|
|
3109
|
+
enum BlockTransactionDetails {
|
|
3110
|
+
ACCOUNTS
|
|
3111
|
+
FULL
|
|
3112
|
+
NONE
|
|
3113
|
+
SIGNATURES
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
enum Commitment {
|
|
3117
|
+
CONFIRMED
|
|
3118
|
+
FINALIZED
|
|
3119
|
+
PROCESSED
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
input DataSlice {
|
|
3123
|
+
offset: Int!
|
|
3124
|
+
length: Int!
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
input ProgramAccountsFilter {
|
|
3128
|
+
bytes: BigInt
|
|
3129
|
+
dataSize: BigInt
|
|
3130
|
+
encoding: AccountEncoding
|
|
3131
|
+
offset: BigInt
|
|
3132
|
+
}
|
|
3133
|
+
|
|
3134
|
+
type ReturnData {
|
|
3135
|
+
data: Base64EncodedBytes
|
|
3136
|
+
programId: Address
|
|
3137
|
+
}
|
|
3138
|
+
|
|
3139
|
+
type Reward {
|
|
3140
|
+
commission: Int
|
|
3141
|
+
lamports: BigInt
|
|
3142
|
+
postBalance: BigInt
|
|
3143
|
+
pubkey: Address
|
|
3144
|
+
rewardType: String
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
scalar Signature
|
|
3148
|
+
|
|
3149
|
+
scalar Slot
|
|
3150
|
+
|
|
3151
|
+
type TokenAmount {
|
|
3152
|
+
amount: String
|
|
3153
|
+
decimals: Int
|
|
3154
|
+
uiAmount: BigInt
|
|
3155
|
+
uiAmountString: String
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3158
|
+
type TokenBalance {
|
|
3159
|
+
accountIndex: Int
|
|
3160
|
+
mint: Account
|
|
3161
|
+
owner: Account
|
|
3162
|
+
programId: Address
|
|
3163
|
+
uiTokenAmount: TokenAmount
|
|
3164
|
+
}
|
|
3165
|
+
|
|
3166
|
+
enum TransactionEncoding {
|
|
3167
|
+
BASE_58
|
|
3168
|
+
BASE_64
|
|
3169
|
+
PARSED
|
|
3170
|
+
}
|
|
3171
|
+
|
|
3172
|
+
enum TransactionVersion {
|
|
3173
|
+
LEGACY
|
|
3174
|
+
ZERO
|
|
3175
|
+
}
|
|
3176
|
+
`
|
|
3177
|
+
);
|
|
3178
|
+
|
|
2888
3179
|
// src/schema/index.ts
|
|
2889
3180
|
function createSolanaGraphQLTypeDefs() {
|
|
2890
|
-
return [
|
|
2891
|
-
accountTypeDefs,
|
|
2892
|
-
blockTypeDefs,
|
|
2893
|
-
commonTypeDefs,
|
|
2894
|
-
inputTypeDefs,
|
|
2895
|
-
instructionTypeDefs,
|
|
2896
|
-
rootTypeDefs,
|
|
2897
|
-
scalarTypeDefs,
|
|
2898
|
-
transactionTypeDefs
|
|
2899
|
-
];
|
|
3181
|
+
return [accountTypeDefs, blockTypeDefs, instructionTypeDefs, rootTypeDefs, typeTypeDefs, transactionTypeDefs];
|
|
2900
3182
|
}
|
|
2901
3183
|
|
|
2902
3184
|
// src/index.ts
|
|
2903
|
-
function createRpcGraphQL(rpc) {
|
|
2904
|
-
const
|
|
3185
|
+
function createRpcGraphQL(rpc, config) {
|
|
3186
|
+
const rpcGraphQLConfig = {
|
|
3187
|
+
maxDataSliceByteRange: config?.maxDataSliceByteRange ?? 200,
|
|
3188
|
+
maxMultipleAccountsBatchSize: config?.maxMultipleAccountsBatchSize ?? 100
|
|
3189
|
+
};
|
|
2905
3190
|
const schema$1 = schema.makeExecutableSchema({
|
|
2906
3191
|
resolvers: createSolanaGraphQLResolvers(),
|
|
2907
3192
|
typeDefs: createSolanaGraphQLTypeDefs()
|
|
2908
3193
|
});
|
|
2909
3194
|
return {
|
|
2910
3195
|
async query(source, variableValues) {
|
|
3196
|
+
const contextValue = createSolanaGraphQLContext(rpc, rpcGraphQLConfig);
|
|
2911
3197
|
return graphql.graphql({
|
|
2912
3198
|
contextValue,
|
|
2913
3199
|
schema: schema$1,
|