@solana/rpc-graphql 2.0.0-experimental.dd2096e → 2.0.0-experimental.e15a66f
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 +673 -353
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +674 -354
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +674 -354
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +673 -353
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +674 -354
- package/dist/index.node.js.map +1 -1
- package/dist/types/context.d.ts +15 -3
- 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 +12 -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/coalescer.d.ts +48 -0
- package/dist/types/loaders/coalescer.d.ts.map +1 -0
- 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 +24 -9
- package/dist/types/loaders/loader.d.ts.map +1 -1
- package/dist/types/loaders/program-accounts.d.ts +6 -3
- 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 +12 -3
- package/dist/types/resolvers/program-accounts.d.ts.map +1 -1
- package/dist/types/resolvers/resolve-info/account.d.ts +15 -0
- package/dist/types/resolvers/resolve-info/account.d.ts.map +1 -0
- package/dist/types/resolvers/resolve-info/index.d.ts +4 -0
- package/dist/types/resolvers/resolve-info/index.d.ts.map +1 -0
- package/dist/types/resolvers/resolve-info/program-accounts.d.ts +20 -0
- package/dist/types/resolvers/resolve-info/program-accounts.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.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { makeExecutableSchema } from '@graphql-tools/schema';
|
|
2
|
-
import { graphql, Kind } from 'graphql';
|
|
2
|
+
import { graphql, Kind, visit, BREAK, isInterfaceType } from 'graphql';
|
|
3
|
+
import { getBase64Codec, getBase58Codec } from '@solana/codecs-strings';
|
|
3
4
|
import DataLoader from 'dataloader';
|
|
4
5
|
import stringify from 'json-stable-stringify';
|
|
5
6
|
|
|
@@ -12,40 +13,225 @@ function replacer(_, value) {
|
|
|
12
13
|
}
|
|
13
14
|
var cacheKeyFn = (obj) => stringify(obj, { replacer });
|
|
14
15
|
|
|
16
|
+
// src/loaders/coalescer.ts
|
|
17
|
+
var hashOmit = (args, omit) => {
|
|
18
|
+
const argsObj = {};
|
|
19
|
+
for (const [key, value] of Object.entries(args)) {
|
|
20
|
+
if (!omit.includes(key)) {
|
|
21
|
+
argsObj[key] = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return cacheKeyFn(argsObj);
|
|
25
|
+
};
|
|
26
|
+
function buildCoalescedFetchesByArgsHashWithDataSlice(toFetchMap, maxDataSliceByteRange) {
|
|
27
|
+
const fetchesByArgsHash = {};
|
|
28
|
+
const orphanedFetches = {};
|
|
29
|
+
Object.entries(toFetchMap).forEach(([address, toFetch]) => {
|
|
30
|
+
toFetch.forEach(({ args, promiseCallback }) => {
|
|
31
|
+
if (!args.encoding) {
|
|
32
|
+
const toFetch2 = orphanedFetches[address] ||= [];
|
|
33
|
+
toFetch2.push({ args, promiseCallback });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (args.encoding != "base64+zstd" && args.dataSlice) {
|
|
37
|
+
const r = args.dataSlice;
|
|
38
|
+
for (const { fetches: fetchAddresses, args: fetchArgs } of Object.values(fetchesByArgsHash)) {
|
|
39
|
+
const addCallbackWithDataSlice = (updateDataSlice) => {
|
|
40
|
+
const { callbacks: promiseCallbacksForAddress2 } = fetchAddresses[address] ||= {
|
|
41
|
+
callbacks: []
|
|
42
|
+
};
|
|
43
|
+
promiseCallbacksForAddress2.push({
|
|
44
|
+
callback: promiseCallback,
|
|
45
|
+
dataSlice: args.dataSlice ?? null
|
|
46
|
+
});
|
|
47
|
+
if (fetchArgs.dataSlice && updateDataSlice) {
|
|
48
|
+
fetchArgs.dataSlice = updateDataSlice;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
if (hashOmit(args, ["dataSlice"]) === hashOmit(fetchArgs, ["dataSlice"])) {
|
|
52
|
+
if (fetchArgs.dataSlice) {
|
|
53
|
+
const g = fetchArgs.dataSlice;
|
|
54
|
+
if (r.offset <= g.offset && g.offset - r.offset + r.length <= maxDataSliceByteRange) {
|
|
55
|
+
const length = Math.max(r.length, g.offset + g.length - r.offset);
|
|
56
|
+
const offset = r.offset;
|
|
57
|
+
addCallbackWithDataSlice({ length, offset });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (r.offset >= g.offset && r.offset - g.offset + g.length <= maxDataSliceByteRange) {
|
|
61
|
+
const length = Math.max(g.length, r.offset + r.length - g.offset);
|
|
62
|
+
const offset = g.offset;
|
|
63
|
+
addCallbackWithDataSlice({ length, offset });
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const { length, offset } = r;
|
|
68
|
+
addCallbackWithDataSlice({ length, offset });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const argsHash = hashOmit(args, []);
|
|
75
|
+
const accountFetches = fetchesByArgsHash[argsHash] ||= {
|
|
76
|
+
args,
|
|
77
|
+
fetches: {}
|
|
78
|
+
};
|
|
79
|
+
const { callbacks: promiseCallbacksForAddress } = accountFetches.fetches[address] ||= {
|
|
80
|
+
callbacks: []
|
|
81
|
+
};
|
|
82
|
+
promiseCallbacksForAddress.push({ callback: promiseCallback, dataSlice: args.dataSlice ?? null });
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
Object.entries(orphanedFetches).forEach(([address, toFetch]) => {
|
|
86
|
+
toFetch.forEach(({ args: orphanedArgs, promiseCallback: orphanPromiseCallback }) => {
|
|
87
|
+
if (Object.keys(fetchesByArgsHash).length !== 0) {
|
|
88
|
+
for (const { fetches, args: args2 } of Object.values(fetchesByArgsHash)) {
|
|
89
|
+
if (hashOmit(orphanedArgs, ["encoding", "dataSlice"]) === hashOmit(args2, ["encoding", "dataSlice"])) {
|
|
90
|
+
const { callbacks: promiseCallbacksForAddress2 } = fetches[address] ||= {
|
|
91
|
+
callbacks: []
|
|
92
|
+
};
|
|
93
|
+
promiseCallbacksForAddress2.push({ callback: orphanPromiseCallback });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const args = { ...orphanedArgs, encoding: "base64" };
|
|
99
|
+
const argsHash = hashOmit(args, []);
|
|
100
|
+
const accountFetches = fetchesByArgsHash[argsHash] ||= {
|
|
101
|
+
args,
|
|
102
|
+
fetches: {}
|
|
103
|
+
};
|
|
104
|
+
const { callbacks: promiseCallbacksForAddress } = accountFetches.fetches[address] ||= {
|
|
105
|
+
callbacks: []
|
|
106
|
+
};
|
|
107
|
+
promiseCallbacksForAddress.push({ callback: orphanPromiseCallback });
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
return fetchesByArgsHash;
|
|
111
|
+
}
|
|
112
|
+
|
|
15
113
|
// src/loaders/account.ts
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
encoding
|
|
28
|
-
|
|
29
|
-
|
|
114
|
+
function getCodec(encoding) {
|
|
115
|
+
switch (encoding) {
|
|
116
|
+
case "base58":
|
|
117
|
+
return getBase58Codec();
|
|
118
|
+
default:
|
|
119
|
+
return getBase64Codec();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function sliceData(account, dataSlice, masterDataSlice) {
|
|
123
|
+
if (dataSlice) {
|
|
124
|
+
const masterOffset = masterDataSlice ? masterDataSlice.offset : 0;
|
|
125
|
+
const slicedData = (data, encoding) => {
|
|
126
|
+
if (encoding === "base64+zstd") {
|
|
127
|
+
return data;
|
|
128
|
+
}
|
|
129
|
+
const { offset, length } = dataSlice;
|
|
130
|
+
const trueOffset = offset - masterOffset;
|
|
131
|
+
const codec = getCodec(encoding);
|
|
132
|
+
return codec.decode(codec.encode(data).slice(trueOffset, trueOffset + length));
|
|
133
|
+
};
|
|
134
|
+
if (Array.isArray(account.data)) {
|
|
135
|
+
const [data, encoding] = account.data;
|
|
136
|
+
return {
|
|
137
|
+
...account,
|
|
138
|
+
data: [slicedData(data, encoding), encoding]
|
|
139
|
+
};
|
|
140
|
+
} else if (typeof account.data === "string") {
|
|
141
|
+
const data = account.data;
|
|
142
|
+
return {
|
|
143
|
+
...account,
|
|
144
|
+
data: slicedData(data, "base58")
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return account;
|
|
30
149
|
}
|
|
31
150
|
async function loadAccount(rpc, { address, ...config }) {
|
|
32
151
|
return await rpc.getAccountInfo(address, config).send().then((res) => res.value);
|
|
33
152
|
}
|
|
34
|
-
function
|
|
153
|
+
async function loadMultipleAccounts(rpc, { addresses, ...config }) {
|
|
154
|
+
return await rpc.getMultipleAccounts(addresses, config).send().then((res) => res.value);
|
|
155
|
+
}
|
|
156
|
+
function createAccountBatchLoadFn(rpc, config) {
|
|
35
157
|
const resolveAccountUsingRpc = loadAccount.bind(null, rpc);
|
|
158
|
+
const resolveMultipleAccountsUsingRpc = loadMultipleAccounts.bind(null, rpc);
|
|
36
159
|
return async (accountQueryArgs) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
160
|
+
const accountsToFetch = {};
|
|
161
|
+
try {
|
|
162
|
+
return Promise.all(
|
|
163
|
+
accountQueryArgs.map(
|
|
164
|
+
({ address, ...args }) => new Promise((resolve, reject) => {
|
|
165
|
+
const accountRecords = accountsToFetch[address] ||= [];
|
|
166
|
+
if (!args.commitment) {
|
|
167
|
+
args.commitment = "confirmed";
|
|
168
|
+
}
|
|
169
|
+
accountRecords.push({ args, promiseCallback: { reject, resolve } });
|
|
170
|
+
})
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
} finally {
|
|
174
|
+
const { maxDataSliceByteRange, maxMultipleAccountsBatchSize } = config;
|
|
175
|
+
const accountFetchesByArgsHash = buildCoalescedFetchesByArgsHashWithDataSlice(
|
|
176
|
+
accountsToFetch,
|
|
177
|
+
maxDataSliceByteRange
|
|
178
|
+
);
|
|
179
|
+
Object.values(accountFetchesByArgsHash).map(({ args, fetches: 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
|
+
}
|
|
40
225
|
};
|
|
41
226
|
}
|
|
42
|
-
function createAccountLoader(rpc) {
|
|
43
|
-
const loader = new DataLoader(createAccountBatchLoadFn(rpc), { cacheKeyFn });
|
|
227
|
+
function createAccountLoader(rpc, config) {
|
|
228
|
+
const loader = new DataLoader(createAccountBatchLoadFn(rpc, config), { cacheKeyFn });
|
|
44
229
|
return {
|
|
45
|
-
load: async (args) => loader.load(
|
|
230
|
+
load: async (args) => loader.load(args),
|
|
231
|
+
loadMany: async (args) => loader.loadMany(args)
|
|
46
232
|
};
|
|
47
233
|
}
|
|
48
|
-
function
|
|
234
|
+
function applyDefaultArgs({
|
|
49
235
|
slot,
|
|
50
236
|
commitment,
|
|
51
237
|
encoding = "jsonParsed",
|
|
@@ -65,61 +251,75 @@ function applyDefaultArgs2({
|
|
|
65
251
|
async function loadBlock(rpc, { slot, ...config }) {
|
|
66
252
|
return await rpc.getBlock(
|
|
67
253
|
slot,
|
|
68
|
-
// @ts-expect-error FIX ME: https://github.com/
|
|
254
|
+
// @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
|
|
69
255
|
config
|
|
70
256
|
).send();
|
|
71
257
|
}
|
|
72
258
|
function createBlockBatchLoadFn(rpc) {
|
|
73
259
|
const resolveBlockUsingRpc = loadBlock.bind(null, rpc);
|
|
74
|
-
return async (blockQueryArgs) =>
|
|
75
|
-
return await Promise.all(blockQueryArgs.map(async (args) => await resolveBlockUsingRpc(applyDefaultArgs2(args))));
|
|
76
|
-
};
|
|
260
|
+
return async (blockQueryArgs) => Promise.all(blockQueryArgs.map(async (args) => resolveBlockUsingRpc(applyDefaultArgs(args))));
|
|
77
261
|
}
|
|
78
262
|
function createBlockLoader(rpc) {
|
|
79
263
|
const loader = new DataLoader(createBlockBatchLoadFn(rpc), { cacheKeyFn });
|
|
80
264
|
return {
|
|
81
|
-
load: async (args) => loader.load(
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
function applyDefaultArgs3({
|
|
85
|
-
commitment,
|
|
86
|
-
dataSlice,
|
|
87
|
-
encoding = "jsonParsed",
|
|
88
|
-
filters,
|
|
89
|
-
minContextSlot,
|
|
90
|
-
programAddress
|
|
91
|
-
}) {
|
|
92
|
-
return {
|
|
93
|
-
commitment,
|
|
94
|
-
dataSlice,
|
|
95
|
-
encoding,
|
|
96
|
-
filters,
|
|
97
|
-
minContextSlot,
|
|
98
|
-
programAddress
|
|
265
|
+
load: async (args) => loader.load(applyDefaultArgs(args)),
|
|
266
|
+
loadMany: async (args) => loader.loadMany(args.map(applyDefaultArgs))
|
|
99
267
|
};
|
|
100
268
|
}
|
|
101
269
|
async function loadProgramAccounts(rpc, { programAddress, ...config }) {
|
|
102
270
|
return await rpc.getProgramAccounts(
|
|
103
271
|
programAddress,
|
|
104
|
-
// @ts-expect-error FIX ME: https://github.com/
|
|
272
|
+
// @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
|
|
105
273
|
config
|
|
106
274
|
).send();
|
|
107
275
|
}
|
|
108
|
-
function createProgramAccountsBatchLoadFn(rpc) {
|
|
276
|
+
function createProgramAccountsBatchLoadFn(rpc, config) {
|
|
109
277
|
const resolveProgramAccountsUsingRpc = loadProgramAccounts.bind(null, rpc);
|
|
110
|
-
return async (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
278
|
+
return async (accountQueryArgs) => {
|
|
279
|
+
const programAccountsToFetch = {};
|
|
280
|
+
try {
|
|
281
|
+
return Promise.all(accountQueryArgs.map(
|
|
282
|
+
({ programAddress, ...args }) => new Promise((resolve, reject) => {
|
|
283
|
+
const accountRecords = programAccountsToFetch[programAddress] ||= [];
|
|
284
|
+
if (!args.commitment) {
|
|
285
|
+
args.commitment = "confirmed";
|
|
286
|
+
}
|
|
287
|
+
accountRecords.push({ args, promiseCallback: { reject, resolve } });
|
|
288
|
+
})
|
|
289
|
+
));
|
|
290
|
+
} finally {
|
|
291
|
+
const { maxDataSliceByteRange } = config;
|
|
292
|
+
const programAccountsFetchesByArgsHash = buildCoalescedFetchesByArgsHashWithDataSlice(programAccountsToFetch, maxDataSliceByteRange);
|
|
293
|
+
Object.values(programAccountsFetchesByArgsHash).map(({ args, fetches: programAddressCallbacks }) => {
|
|
294
|
+
return Object.entries(programAddressCallbacks).map(([programAddress, { callbacks }]) => {
|
|
295
|
+
return Array.from({ length: 1 }, async () => {
|
|
296
|
+
try {
|
|
297
|
+
const result = await resolveProgramAccountsUsingRpc({
|
|
298
|
+
programAddress,
|
|
299
|
+
...args
|
|
300
|
+
});
|
|
301
|
+
callbacks.forEach(({ callback, dataSlice }) => {
|
|
302
|
+
callback.resolve(sliceData(result, dataSlice, args.dataSlice));
|
|
303
|
+
});
|
|
304
|
+
} catch (e) {
|
|
305
|
+
callbacks.forEach(({ callback }) => {
|
|
306
|
+
callback.reject(e);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
}
|
|
114
313
|
};
|
|
115
314
|
}
|
|
116
|
-
function createProgramAccountsLoader(rpc) {
|
|
117
|
-
const loader = new DataLoader(createProgramAccountsBatchLoadFn(rpc), { cacheKeyFn });
|
|
315
|
+
function createProgramAccountsLoader(rpc, config) {
|
|
316
|
+
const loader = new DataLoader(createProgramAccountsBatchLoadFn(rpc, config), { cacheKeyFn });
|
|
118
317
|
return {
|
|
119
|
-
load: async (args) => loader.load(
|
|
318
|
+
load: async (args) => loader.load(args),
|
|
319
|
+
loadMany: async (args) => loader.loadMany(args)
|
|
120
320
|
};
|
|
121
321
|
}
|
|
122
|
-
function
|
|
322
|
+
function applyDefaultArgs2({
|
|
123
323
|
commitment,
|
|
124
324
|
encoding = "jsonParsed",
|
|
125
325
|
signature
|
|
@@ -133,170 +333,280 @@ function applyDefaultArgs4({
|
|
|
133
333
|
async function loadTransaction(rpc, { signature, ...config }) {
|
|
134
334
|
return await rpc.getTransaction(
|
|
135
335
|
signature,
|
|
136
|
-
// @ts-expect-error FIX ME: https://github.com/
|
|
336
|
+
// @ts-expect-error FIX ME: https://github.com/microsoft/TypeScript/issues/43187
|
|
137
337
|
config
|
|
138
338
|
).send();
|
|
139
339
|
}
|
|
140
340
|
function createTransactionBatchLoadFn(rpc) {
|
|
141
341
|
const resolveTransactionUsingRpc = loadTransaction.bind(null, rpc);
|
|
142
|
-
return async (transactionQueryArgs) =>
|
|
143
|
-
return await Promise.all(
|
|
144
|
-
transactionQueryArgs.map(async (args) => await resolveTransactionUsingRpc(applyDefaultArgs4(args)))
|
|
145
|
-
);
|
|
146
|
-
};
|
|
342
|
+
return async (transactionQueryArgs) => Promise.all(transactionQueryArgs.map(async (args) => resolveTransactionUsingRpc(applyDefaultArgs2(args))));
|
|
147
343
|
}
|
|
148
344
|
function createTransactionLoader(rpc) {
|
|
149
345
|
const loader = new DataLoader(createTransactionBatchLoadFn(rpc), { cacheKeyFn });
|
|
150
346
|
return {
|
|
151
|
-
load: async (args) => loader.load(
|
|
347
|
+
load: async (args) => loader.load(applyDefaultArgs2(args)),
|
|
348
|
+
loadMany: async (args) => loader.loadMany(args.map(applyDefaultArgs2))
|
|
152
349
|
};
|
|
153
350
|
}
|
|
154
351
|
|
|
155
352
|
// src/context.ts
|
|
156
|
-
function createSolanaGraphQLContext(rpc) {
|
|
353
|
+
function createSolanaGraphQLContext(rpc, config) {
|
|
157
354
|
return {
|
|
158
355
|
loaders: {
|
|
159
|
-
account: createAccountLoader(rpc),
|
|
356
|
+
account: createAccountLoader(rpc, config),
|
|
160
357
|
block: createBlockLoader(rpc),
|
|
161
|
-
programAccounts: createProgramAccountsLoader(rpc),
|
|
358
|
+
programAccounts: createProgramAccountsLoader(rpc, config),
|
|
162
359
|
transaction: createTransactionLoader(rpc)
|
|
163
360
|
}
|
|
164
361
|
};
|
|
165
362
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
return
|
|
363
|
+
function injectableRootVisitor(info, rootNode, operations) {
|
|
364
|
+
const { fieldNodes } = info;
|
|
365
|
+
const root = rootNode ?? fieldNodes[0];
|
|
366
|
+
const parentIsRoot = (ancestors) => (Array.isArray(ancestors) ? ancestors[0] : ancestors) === root;
|
|
367
|
+
visit(root, {
|
|
368
|
+
Field(node, key, parent, path, ancestors) {
|
|
369
|
+
if (!parentIsRoot(ancestors))
|
|
370
|
+
return;
|
|
371
|
+
return operations.fieldNodeOperation(info, node, key, parent, path, ancestors);
|
|
372
|
+
},
|
|
373
|
+
FragmentSpread(node, key, parent, path, ancestors) {
|
|
374
|
+
const fragmentDefinition = info.fragments[node.name.value];
|
|
375
|
+
return operations.fragmentSpreadNodeOperation(info, fragmentDefinition, node, key, parent, path, ancestors);
|
|
376
|
+
},
|
|
377
|
+
InlineFragment(node, key, parent, path, ancestors) {
|
|
378
|
+
if (!parentIsRoot(ancestors))
|
|
379
|
+
return;
|
|
380
|
+
return operations.inlineFragmentNodeOperation(info, node, key, parent, path, ancestors);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
function onlyFieldsRequested(fieldNames, info, rootNode) {
|
|
385
|
+
let onlyFieldsRequested2 = true;
|
|
386
|
+
function checkFieldsWithVisitor(root) {
|
|
387
|
+
injectableRootVisitor(info, root, {
|
|
388
|
+
fieldNodeOperation(_info, node) {
|
|
389
|
+
onlyFieldsRequested2 = fieldNames.includes(node.name.value);
|
|
390
|
+
if (!onlyFieldsRequested2) {
|
|
391
|
+
return BREAK;
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
fragmentSpreadNodeOperation(_info, fragment) {
|
|
395
|
+
checkFieldsWithVisitor(fragment);
|
|
396
|
+
},
|
|
397
|
+
inlineFragmentNodeOperation(_info, node) {
|
|
398
|
+
checkFieldsWithVisitor(node);
|
|
174
399
|
}
|
|
175
|
-
return null;
|
|
176
400
|
});
|
|
177
|
-
|
|
178
|
-
|
|
401
|
+
}
|
|
402
|
+
checkFieldsWithVisitor(rootNode ?? null);
|
|
403
|
+
return onlyFieldsRequested2;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/resolvers/resolve-info/account.ts
|
|
407
|
+
function findArgumentNodeByName(argumentNodes, name) {
|
|
408
|
+
return argumentNodes.find((argumentNode) => argumentNode.name.value === name);
|
|
409
|
+
}
|
|
410
|
+
function parseAccountEncodingArgument(argumentNodes, variableValues) {
|
|
411
|
+
const argumentNode = findArgumentNodeByName(argumentNodes, "encoding");
|
|
412
|
+
if (argumentNode) {
|
|
413
|
+
if (argumentNode.value.kind === "EnumValue") {
|
|
414
|
+
if (argumentNode.value.value === "BASE_58") {
|
|
415
|
+
return "base58";
|
|
416
|
+
}
|
|
417
|
+
if (argumentNode.value.value === "BASE_64") {
|
|
418
|
+
return "base64";
|
|
419
|
+
}
|
|
420
|
+
if (argumentNode.value.value === "BASE_64_ZSTD") {
|
|
421
|
+
return "base64+zstd";
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (argumentNode.value.kind === "Variable") {
|
|
425
|
+
return variableValues[argumentNode.value.name.value];
|
|
426
|
+
}
|
|
427
|
+
} else {
|
|
428
|
+
return void 0;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
function parseAccountDataSliceArgument(argumentNodes, variableValues) {
|
|
432
|
+
const argumentNode = findArgumentNodeByName(argumentNodes, "dataSlice");
|
|
433
|
+
if (argumentNode) {
|
|
434
|
+
if (argumentNode.value.kind === "ObjectValue") {
|
|
435
|
+
const offsetArg = argumentNode.value.fields?.find((field) => field.name.value === "offset");
|
|
436
|
+
const lengthArg = argumentNode.value.fields?.find((field) => field.name.value === "length");
|
|
437
|
+
const length = lengthArg?.value.kind === "IntValue" ? parseInt(lengthArg.value.value) : lengthArg?.value.kind === "Variable" ? variableValues[lengthArg.value.name.value] : void 0;
|
|
438
|
+
const offset = offsetArg?.value.kind === "IntValue" ? parseInt(offsetArg.value.value) : offsetArg?.value.kind === "Variable" ? variableValues[offsetArg.value.name.value] : void 0;
|
|
439
|
+
return length !== void 0 && length !== null && offset !== void 0 && offset !== null ? { length, offset } : void 0;
|
|
440
|
+
}
|
|
441
|
+
if (argumentNode.value.kind === "Variable") {
|
|
442
|
+
return variableValues[argumentNode.value.name.value];
|
|
179
443
|
}
|
|
444
|
+
} else {
|
|
445
|
+
return void 0;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function buildAccountArgSetWithVisitor(args, info) {
|
|
449
|
+
const argSet = [args];
|
|
450
|
+
function buildArgSetWithVisitor(root) {
|
|
451
|
+
injectableRootVisitor(info, root, {
|
|
452
|
+
fieldNodeOperation(info2, node) {
|
|
453
|
+
if (node.name.value !== "data") {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (node.arguments) {
|
|
457
|
+
const { variableValues } = info2;
|
|
458
|
+
const encoding = parseAccountEncodingArgument(node.arguments, variableValues);
|
|
459
|
+
const dataSlice = parseAccountDataSliceArgument(node.arguments, variableValues);
|
|
460
|
+
argSet.push({ ...args, dataSlice, encoding });
|
|
461
|
+
}
|
|
462
|
+
},
|
|
463
|
+
fragmentSpreadNodeOperation(_info, fragment) {
|
|
464
|
+
buildArgSetWithVisitor(fragment);
|
|
465
|
+
},
|
|
466
|
+
inlineFragmentNodeOperation(info2, node) {
|
|
467
|
+
const { schema } = info2;
|
|
468
|
+
const accountInterface = schema.getType("Account");
|
|
469
|
+
if (isInterfaceType(accountInterface) && // Recursively check if the inline fragment requests any
|
|
470
|
+
// fields outside of the `Account` interface.
|
|
471
|
+
!onlyFieldsRequested(Object.keys(accountInterface.getFields()), info2, node)) {
|
|
472
|
+
argSet.push({ ...args, encoding: "jsonParsed" });
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
});
|
|
180
476
|
}
|
|
181
|
-
|
|
477
|
+
buildArgSetWithVisitor(null);
|
|
478
|
+
return argSet;
|
|
479
|
+
}
|
|
480
|
+
function buildAccountLoaderArgSetFromResolveInfo(args, info) {
|
|
481
|
+
return buildAccountArgSetWithVisitor(args, info);
|
|
182
482
|
}
|
|
183
483
|
|
|
184
|
-
// src/resolvers/
|
|
185
|
-
function
|
|
186
|
-
|
|
187
|
-
parsed: { info: result, type: accountType },
|
|
188
|
-
program: programName,
|
|
189
|
-
programId
|
|
190
|
-
} = parsedAccountData;
|
|
191
|
-
result.accountType = accountType;
|
|
192
|
-
result.programId = programId;
|
|
193
|
-
result.programName = programName;
|
|
194
|
-
return result;
|
|
484
|
+
// src/resolvers/resolve-info/program-accounts.ts
|
|
485
|
+
function buildProgramAccountsLoaderArgSetFromResolveInfo(args, info) {
|
|
486
|
+
return buildAccountArgSetWithVisitor(args, info);
|
|
195
487
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const [
|
|
202
|
-
// The account's data, either encoded or parsed.
|
|
203
|
-
data,
|
|
204
|
-
// Tells GraphQL which encoding has been returned
|
|
205
|
-
// by the RPC.
|
|
206
|
-
responseEncoding
|
|
207
|
-
] = Array.isArray(account.data) ? encoding === "jsonParsed" ? (
|
|
208
|
-
// The requested encoding is jsonParsed,
|
|
209
|
-
// but the data could not be parsed.
|
|
210
|
-
// Defaults to base64 encoding.
|
|
211
|
-
[{ data: account.data[0] }, "base64"]
|
|
212
|
-
) : (
|
|
213
|
-
// The requested encoding is base58,
|
|
214
|
-
// base64, or base64+zstd.
|
|
215
|
-
[{ data: account.data[0] }, encoding]
|
|
216
|
-
) : (
|
|
217
|
-
// The account data was returned as an object,
|
|
218
|
-
// so it was parsed successfully.
|
|
219
|
-
[transformParsedAccountData(account.data), "jsonParsed"]
|
|
220
|
-
);
|
|
221
|
-
account.address = address;
|
|
222
|
-
account.encoding = responseEncoding;
|
|
223
|
-
account.ownerProgram = account.owner;
|
|
224
|
-
return {
|
|
225
|
-
...account,
|
|
226
|
-
...data
|
|
488
|
+
|
|
489
|
+
// src/resolvers/account.ts
|
|
490
|
+
var resolveAccountData = () => {
|
|
491
|
+
return (parent, args) => {
|
|
492
|
+
return parent === null ? null : parent.encodedData ? parent.encodedData[cacheKeyFn(args)] : null;
|
|
227
493
|
};
|
|
228
|
-
}
|
|
494
|
+
};
|
|
229
495
|
var resolveAccount = (fieldName) => {
|
|
230
496
|
return async (parent, args, context, info) => {
|
|
231
497
|
const address = fieldName ? parent[fieldName] : args.address;
|
|
232
|
-
if (
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (onlyPresentFieldRequested("address", info)) {
|
|
236
|
-
return { address };
|
|
237
|
-
}
|
|
238
|
-
const account = await context.loaders.account.load({ ...args, address });
|
|
239
|
-
return account === null ? { address } : transformLoadedAccount({ account, address, encoding: args.encoding });
|
|
240
|
-
};
|
|
241
|
-
};
|
|
242
|
-
var accountResolvers = {
|
|
243
|
-
Account: {
|
|
244
|
-
__resolveType(account) {
|
|
245
|
-
if (account.encoding === "base58") {
|
|
246
|
-
return "AccountBase58";
|
|
247
|
-
}
|
|
248
|
-
if (account.encoding === "base64") {
|
|
249
|
-
return "AccountBase64";
|
|
498
|
+
if (address) {
|
|
499
|
+
if (onlyFieldsRequested(["address"], info)) {
|
|
500
|
+
return { address };
|
|
250
501
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (account
|
|
259
|
-
|
|
502
|
+
const argsSet = buildAccountLoaderArgSetFromResolveInfo({ ...args, address }, info);
|
|
503
|
+
const loadedAccounts = await context.loaders.account.loadMany(argsSet);
|
|
504
|
+
let result = {
|
|
505
|
+
address,
|
|
506
|
+
encodedData: {}
|
|
507
|
+
};
|
|
508
|
+
loadedAccounts.forEach((account, i) => {
|
|
509
|
+
if (account instanceof Error) {
|
|
510
|
+
console.error(account);
|
|
511
|
+
return;
|
|
260
512
|
}
|
|
261
|
-
if (account
|
|
262
|
-
return
|
|
513
|
+
if (account === null) {
|
|
514
|
+
return;
|
|
263
515
|
}
|
|
264
|
-
if (
|
|
265
|
-
|
|
516
|
+
if (!result.ownerProgram) {
|
|
517
|
+
result = {
|
|
518
|
+
...result,
|
|
519
|
+
...account,
|
|
520
|
+
ownerProgram: account.owner
|
|
521
|
+
};
|
|
266
522
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
523
|
+
const { data } = account;
|
|
524
|
+
const { encoding, dataSlice } = argsSet[i];
|
|
525
|
+
if (encoding && result.encodedData) {
|
|
526
|
+
if (Array.isArray(data)) {
|
|
527
|
+
result.encodedData[cacheKeyFn({
|
|
528
|
+
dataSlice,
|
|
529
|
+
encoding: encoding === "jsonParsed" ? "base64" : encoding
|
|
530
|
+
})] = data[0];
|
|
531
|
+
} else if (typeof data === "string") {
|
|
532
|
+
result.encodedData[cacheKeyFn({
|
|
533
|
+
dataSlice,
|
|
534
|
+
encoding: "base58"
|
|
535
|
+
})] = data;
|
|
536
|
+
} else if (typeof data === "object") {
|
|
537
|
+
const {
|
|
538
|
+
parsed: { info: parsedData, type: accountType },
|
|
539
|
+
program: programName,
|
|
540
|
+
programId
|
|
541
|
+
} = data;
|
|
542
|
+
result.jsonParsedConfigs = {
|
|
543
|
+
accountType,
|
|
544
|
+
programId,
|
|
545
|
+
programName
|
|
546
|
+
};
|
|
547
|
+
result = {
|
|
548
|
+
...result,
|
|
549
|
+
...parsedData
|
|
550
|
+
};
|
|
551
|
+
}
|
|
272
552
|
}
|
|
273
|
-
}
|
|
274
|
-
return
|
|
553
|
+
});
|
|
554
|
+
return result;
|
|
275
555
|
}
|
|
556
|
+
return null;
|
|
557
|
+
};
|
|
558
|
+
};
|
|
559
|
+
function resolveAccountType(accountResult) {
|
|
560
|
+
const { jsonParsedConfigs } = accountResult;
|
|
561
|
+
if (jsonParsedConfigs) {
|
|
562
|
+
if (jsonParsedConfigs.programName === "nonce") {
|
|
563
|
+
return "NonceAccount";
|
|
564
|
+
}
|
|
565
|
+
if (jsonParsedConfigs.accountType === "mint" && jsonParsedConfigs.programName === "spl-token") {
|
|
566
|
+
return "MintAccount";
|
|
567
|
+
}
|
|
568
|
+
if (jsonParsedConfigs.accountType === "account" && jsonParsedConfigs.programName === "spl-token") {
|
|
569
|
+
return "TokenAccount";
|
|
570
|
+
}
|
|
571
|
+
if (jsonParsedConfigs.programName === "stake") {
|
|
572
|
+
return "StakeAccount";
|
|
573
|
+
}
|
|
574
|
+
if (jsonParsedConfigs.accountType === "vote" && jsonParsedConfigs.programName === "vote") {
|
|
575
|
+
return "VoteAccount";
|
|
576
|
+
}
|
|
577
|
+
if (jsonParsedConfigs.accountType === "lookupTable" && jsonParsedConfigs.programName === "address-lookup-table") {
|
|
578
|
+
return "LookupTableAccount";
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return "GenericAccount";
|
|
582
|
+
}
|
|
583
|
+
var accountResolvers = {
|
|
584
|
+
Account: {
|
|
585
|
+
__resolveType: resolveAccountType,
|
|
586
|
+
data: resolveAccountData()
|
|
276
587
|
},
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
},
|
|
280
|
-
AccountBase64: {
|
|
281
|
-
ownerProgram: resolveAccount("ownerProgram")
|
|
282
|
-
},
|
|
283
|
-
AccountBase64Zstd: {
|
|
588
|
+
GenericAccount: {
|
|
589
|
+
data: resolveAccountData(),
|
|
284
590
|
ownerProgram: resolveAccount("ownerProgram")
|
|
285
591
|
},
|
|
286
592
|
LookupTableAccount: {
|
|
287
593
|
authority: resolveAccount("authority"),
|
|
594
|
+
data: resolveAccountData(),
|
|
288
595
|
ownerProgram: resolveAccount("ownerProgram")
|
|
289
596
|
},
|
|
290
597
|
MintAccount: {
|
|
598
|
+
data: resolveAccountData(),
|
|
291
599
|
freezeAuthority: resolveAccount("freezeAuthority"),
|
|
292
600
|
mintAuthority: resolveAccount("mintAuthority"),
|
|
293
601
|
ownerProgram: resolveAccount("ownerProgram")
|
|
294
602
|
},
|
|
295
603
|
NonceAccount: {
|
|
296
604
|
authority: resolveAccount("authority"),
|
|
605
|
+
data: resolveAccountData(),
|
|
297
606
|
ownerProgram: resolveAccount("ownerProgram")
|
|
298
607
|
},
|
|
299
608
|
StakeAccount: {
|
|
609
|
+
data: resolveAccountData(),
|
|
300
610
|
ownerProgram: resolveAccount("ownerProgram")
|
|
301
611
|
},
|
|
302
612
|
StakeAccountDataMetaAuthorized: {
|
|
@@ -310,12 +620,14 @@ var accountResolvers = {
|
|
|
310
620
|
voter: resolveAccount("voter")
|
|
311
621
|
},
|
|
312
622
|
TokenAccount: {
|
|
623
|
+
data: resolveAccountData(),
|
|
313
624
|
mint: resolveAccount("mint"),
|
|
314
625
|
owner: resolveAccount("owner"),
|
|
315
626
|
ownerProgram: resolveAccount("ownerProgram")
|
|
316
627
|
},
|
|
317
628
|
VoteAccount: {
|
|
318
629
|
authorizedWithdrawer: resolveAccount("authorizedWithdrawer"),
|
|
630
|
+
data: resolveAccountData(),
|
|
319
631
|
node: resolveAccount("nodePubkey"),
|
|
320
632
|
ownerProgram: resolveAccount("ownerProgram")
|
|
321
633
|
},
|
|
@@ -375,7 +687,7 @@ function resolveTransaction(fieldName) {
|
|
|
375
687
|
if (!signature) {
|
|
376
688
|
return null;
|
|
377
689
|
}
|
|
378
|
-
if (
|
|
690
|
+
if (onlyFieldsRequested(["signature"], info)) {
|
|
379
691
|
return { signature };
|
|
380
692
|
}
|
|
381
693
|
const transaction = await context.loaders.transaction.load({ ...args, signature });
|
|
@@ -441,7 +753,7 @@ var resolveBlock = (fieldName) => {
|
|
|
441
753
|
if (!slot) {
|
|
442
754
|
return null;
|
|
443
755
|
}
|
|
444
|
-
if (
|
|
756
|
+
if (onlyFieldsRequested(["slot"], info)) {
|
|
445
757
|
return { slot };
|
|
446
758
|
}
|
|
447
759
|
const block = await context.loaders.block.load({ ...args, slot });
|
|
@@ -1190,20 +1502,57 @@ var instructionResolvers = {
|
|
|
1190
1502
|
function resolveProgramAccounts(fieldName) {
|
|
1191
1503
|
return async (parent, args, context, info) => {
|
|
1192
1504
|
const programAddress = fieldName ? parent[fieldName] : args.programAddress;
|
|
1193
|
-
if (
|
|
1194
|
-
|
|
1505
|
+
if (programAddress) {
|
|
1506
|
+
const argsSet = buildProgramAccountsLoaderArgSetFromResolveInfo({ ...args, programAddress }, info);
|
|
1507
|
+
const loadedProgramAccountsLists = await context.loaders.programAccounts.loadMany(argsSet);
|
|
1508
|
+
const result = {};
|
|
1509
|
+
loadedProgramAccountsLists.forEach((programAccounts, i) => {
|
|
1510
|
+
if (programAccounts instanceof Error) {
|
|
1511
|
+
console.error(programAccounts);
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
programAccounts.forEach((programAccount) => {
|
|
1515
|
+
const { account, pubkey: address } = programAccount;
|
|
1516
|
+
const thisResult = result[address] ||= {
|
|
1517
|
+
...account,
|
|
1518
|
+
address,
|
|
1519
|
+
encodedData: {},
|
|
1520
|
+
ownerProgram: account.owner
|
|
1521
|
+
};
|
|
1522
|
+
const { data } = account;
|
|
1523
|
+
const { encoding, dataSlice } = argsSet[i];
|
|
1524
|
+
if (encoding && thisResult.encodedData) {
|
|
1525
|
+
if (Array.isArray(data)) {
|
|
1526
|
+
thisResult.encodedData[cacheKeyFn({
|
|
1527
|
+
dataSlice,
|
|
1528
|
+
encoding: encoding === "jsonParsed" ? "base64" : encoding
|
|
1529
|
+
})] = data[0];
|
|
1530
|
+
} else if (typeof data === "string") {
|
|
1531
|
+
thisResult.encodedData[cacheKeyFn({
|
|
1532
|
+
dataSlice,
|
|
1533
|
+
encoding: "base58"
|
|
1534
|
+
})] = data;
|
|
1535
|
+
} else if (typeof data === "object") {
|
|
1536
|
+
const {
|
|
1537
|
+
parsed: { info: parsedData, type: accountType },
|
|
1538
|
+
program: programName,
|
|
1539
|
+
programId
|
|
1540
|
+
} = data;
|
|
1541
|
+
thisResult.jsonParsedConfigs = {
|
|
1542
|
+
accountType,
|
|
1543
|
+
programId,
|
|
1544
|
+
programName
|
|
1545
|
+
};
|
|
1546
|
+
for (const key in parsedData) {
|
|
1547
|
+
thisResult[key] = parsedData[key];
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
});
|
|
1552
|
+
});
|
|
1553
|
+
return Object.values(result);
|
|
1195
1554
|
}
|
|
1196
|
-
|
|
1197
|
-
return { programAddress };
|
|
1198
|
-
}
|
|
1199
|
-
const programAccounts = await context.loaders.programAccounts.load({ ...args, programAddress });
|
|
1200
|
-
return programAccounts === null ? { programAddress } : programAccounts.map(
|
|
1201
|
-
(programAccount) => transformLoadedAccount({
|
|
1202
|
-
account: programAccount.account,
|
|
1203
|
-
address: programAccount.pubkey,
|
|
1204
|
-
encoding: args.encoding
|
|
1205
|
-
})
|
|
1206
|
-
);
|
|
1555
|
+
return null;
|
|
1207
1556
|
};
|
|
1208
1557
|
}
|
|
1209
1558
|
|
|
@@ -1230,35 +1579,44 @@ var stringScalarAlias = {
|
|
|
1230
1579
|
return value;
|
|
1231
1580
|
}
|
|
1232
1581
|
};
|
|
1233
|
-
var
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
Base64ZstdEncodedBytes: stringScalarAlias,
|
|
1238
|
-
BigInt: {
|
|
1239
|
-
__parseLiteral(ast) {
|
|
1240
|
-
if (ast.kind === Kind.STRING) {
|
|
1241
|
-
return BigInt(ast.value);
|
|
1242
|
-
}
|
|
1243
|
-
return null;
|
|
1244
|
-
},
|
|
1245
|
-
__parseValue(value) {
|
|
1246
|
-
return BigInt(value);
|
|
1247
|
-
},
|
|
1248
|
-
__serialize(value) {
|
|
1249
|
-
return BigInt(value);
|
|
1582
|
+
var bigIntScalarAlias = {
|
|
1583
|
+
__parseLiteral(ast) {
|
|
1584
|
+
if (ast.kind === Kind.STRING) {
|
|
1585
|
+
return BigInt(ast.value);
|
|
1250
1586
|
}
|
|
1587
|
+
return null;
|
|
1588
|
+
},
|
|
1589
|
+
__parseValue(value) {
|
|
1590
|
+
return BigInt(value);
|
|
1591
|
+
},
|
|
1592
|
+
__serialize(value) {
|
|
1593
|
+
return BigInt(value);
|
|
1251
1594
|
}
|
|
1252
1595
|
};
|
|
1253
|
-
|
|
1254
|
-
// src/resolvers/types.ts
|
|
1255
|
-
var commonTypeResolvers = {
|
|
1596
|
+
var typeTypeResolvers = {
|
|
1256
1597
|
AccountEncoding: {
|
|
1257
1598
|
BASE_58: "base58",
|
|
1258
1599
|
BASE_64: "base64",
|
|
1259
|
-
BASE_64_ZSTD: "base64+zstd"
|
|
1260
|
-
PARSED: "jsonParsed"
|
|
1600
|
+
BASE_64_ZSTD: "base64+zstd"
|
|
1261
1601
|
},
|
|
1602
|
+
Address: stringScalarAlias,
|
|
1603
|
+
Base58EncodedBytes: stringScalarAlias,
|
|
1604
|
+
Base64EncodedBytes: stringScalarAlias,
|
|
1605
|
+
Base64ZstdEncodedBytes: stringScalarAlias,
|
|
1606
|
+
BigInt: bigIntScalarAlias,
|
|
1607
|
+
BlockTransactionDetails: {
|
|
1608
|
+
ACCOUNTS: "accounts",
|
|
1609
|
+
FULL: "full",
|
|
1610
|
+
NONE: "none",
|
|
1611
|
+
SIGNATURES: "signatures"
|
|
1612
|
+
},
|
|
1613
|
+
Commitment: {
|
|
1614
|
+
CONFIRMED: "confirmed",
|
|
1615
|
+
FINALIZED: "finalized",
|
|
1616
|
+
PROCESSED: "processed"
|
|
1617
|
+
},
|
|
1618
|
+
Signature: stringScalarAlias,
|
|
1619
|
+
Slot: bigIntScalarAlias,
|
|
1262
1620
|
TokenBalance: {
|
|
1263
1621
|
mint: resolveAccount("mint"),
|
|
1264
1622
|
owner: resolveAccount("owner")
|
|
@@ -1279,11 +1637,10 @@ function createSolanaGraphQLResolvers() {
|
|
|
1279
1637
|
return {
|
|
1280
1638
|
...accountResolvers,
|
|
1281
1639
|
...blockResolvers,
|
|
1282
|
-
...commonTypeResolvers,
|
|
1283
1640
|
...instructionResolvers,
|
|
1284
1641
|
...rootResolvers,
|
|
1285
|
-
...
|
|
1286
|
-
...
|
|
1642
|
+
...transactionResolvers,
|
|
1643
|
+
...typeTypeResolvers
|
|
1287
1644
|
};
|
|
1288
1645
|
}
|
|
1289
1646
|
|
|
@@ -1296,6 +1653,7 @@ var accountTypeDefs = (
|
|
|
1296
1653
|
"""
|
|
1297
1654
|
interface Account {
|
|
1298
1655
|
address: Address
|
|
1656
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1299
1657
|
executable: Boolean
|
|
1300
1658
|
lamports: BigInt
|
|
1301
1659
|
ownerProgram: Account
|
|
@@ -1304,37 +1662,11 @@ var accountTypeDefs = (
|
|
|
1304
1662
|
}
|
|
1305
1663
|
|
|
1306
1664
|
"""
|
|
1307
|
-
|
|
1308
|
-
"""
|
|
1309
|
-
type AccountBase58 implements Account {
|
|
1310
|
-
address: Address
|
|
1311
|
-
data: Base58EncodedBytes
|
|
1312
|
-
executable: Boolean
|
|
1313
|
-
lamports: BigInt
|
|
1314
|
-
ownerProgram: Account
|
|
1315
|
-
space: BigInt
|
|
1316
|
-
rentEpoch: BigInt
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
"""
|
|
1320
|
-
An account with base64 encoded data
|
|
1665
|
+
Generic base account type
|
|
1321
1666
|
"""
|
|
1322
|
-
type
|
|
1667
|
+
type GenericAccount implements Account {
|
|
1323
1668
|
address: Address
|
|
1324
|
-
data:
|
|
1325
|
-
executable: Boolean
|
|
1326
|
-
lamports: BigInt
|
|
1327
|
-
ownerProgram: Account
|
|
1328
|
-
space: BigInt
|
|
1329
|
-
rentEpoch: BigInt
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
"""
|
|
1333
|
-
An account with base64+zstd encoded data
|
|
1334
|
-
"""
|
|
1335
|
-
type AccountBase64Zstd implements Account {
|
|
1336
|
-
address: Address
|
|
1337
|
-
data: Base64ZstdEncodedBytes
|
|
1669
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1338
1670
|
executable: Boolean
|
|
1339
1671
|
lamports: BigInt
|
|
1340
1672
|
ownerProgram: Account
|
|
@@ -1350,6 +1682,7 @@ var accountTypeDefs = (
|
|
|
1350
1682
|
"""
|
|
1351
1683
|
type NonceAccount implements Account {
|
|
1352
1684
|
address: Address
|
|
1685
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1353
1686
|
executable: Boolean
|
|
1354
1687
|
lamports: BigInt
|
|
1355
1688
|
ownerProgram: Account
|
|
@@ -1365,6 +1698,7 @@ var accountTypeDefs = (
|
|
|
1365
1698
|
"""
|
|
1366
1699
|
type LookupTableAccount implements Account {
|
|
1367
1700
|
address: Address
|
|
1701
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1368
1702
|
executable: Boolean
|
|
1369
1703
|
lamports: BigInt
|
|
1370
1704
|
ownerProgram: Account
|
|
@@ -1382,6 +1716,7 @@ var accountTypeDefs = (
|
|
|
1382
1716
|
"""
|
|
1383
1717
|
type MintAccount implements Account {
|
|
1384
1718
|
address: Address
|
|
1719
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1385
1720
|
executable: Boolean
|
|
1386
1721
|
lamports: BigInt
|
|
1387
1722
|
ownerProgram: Account
|
|
@@ -1399,6 +1734,7 @@ var accountTypeDefs = (
|
|
|
1399
1734
|
"""
|
|
1400
1735
|
type TokenAccount implements Account {
|
|
1401
1736
|
address: Address
|
|
1737
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1402
1738
|
executable: Boolean
|
|
1403
1739
|
lamports: BigInt
|
|
1404
1740
|
ownerProgram: Account
|
|
@@ -1441,6 +1777,7 @@ var accountTypeDefs = (
|
|
|
1441
1777
|
"""
|
|
1442
1778
|
type StakeAccount implements Account {
|
|
1443
1779
|
address: Address
|
|
1780
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1444
1781
|
executable: Boolean
|
|
1445
1782
|
lamports: BigInt
|
|
1446
1783
|
ownerProgram: Account
|
|
@@ -1472,6 +1809,7 @@ var accountTypeDefs = (
|
|
|
1472
1809
|
"""
|
|
1473
1810
|
type VoteAccount implements Account {
|
|
1474
1811
|
address: Address
|
|
1812
|
+
data(encoding: AccountEncoding!, dataSlice: DataSlice): String
|
|
1475
1813
|
executable: Boolean
|
|
1476
1814
|
lamports: BigInt
|
|
1477
1815
|
ownerProgram: Account
|
|
@@ -1585,101 +1923,6 @@ var blockTypeDefs = (
|
|
|
1585
1923
|
`
|
|
1586
1924
|
);
|
|
1587
1925
|
|
|
1588
|
-
// src/schema/common/inputs.ts
|
|
1589
|
-
var inputTypeDefs = (
|
|
1590
|
-
/* GraphQL */
|
|
1591
|
-
`
|
|
1592
|
-
input DataSlice {
|
|
1593
|
-
offset: Int
|
|
1594
|
-
length: Int
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
input ProgramAccountsFilter {
|
|
1598
|
-
bytes: BigInt
|
|
1599
|
-
dataSize: BigInt
|
|
1600
|
-
encoding: AccountEncoding
|
|
1601
|
-
offset: BigInt
|
|
1602
|
-
}
|
|
1603
|
-
`
|
|
1604
|
-
);
|
|
1605
|
-
|
|
1606
|
-
// src/schema/common/scalars.ts
|
|
1607
|
-
var scalarTypeDefs = (
|
|
1608
|
-
/* GraphQL */
|
|
1609
|
-
`
|
|
1610
|
-
scalar Address
|
|
1611
|
-
scalar Base58EncodedBytes
|
|
1612
|
-
scalar Base64EncodedBytes
|
|
1613
|
-
scalar Base64ZstdEncodedBytes
|
|
1614
|
-
scalar BigInt
|
|
1615
|
-
`
|
|
1616
|
-
);
|
|
1617
|
-
|
|
1618
|
-
// src/schema/common/types.ts
|
|
1619
|
-
var commonTypeDefs = (
|
|
1620
|
-
/* GraphQL */
|
|
1621
|
-
`
|
|
1622
|
-
enum AccountEncoding {
|
|
1623
|
-
BASE_58
|
|
1624
|
-
BASE_64
|
|
1625
|
-
BASE_64_ZSTD
|
|
1626
|
-
PARSED
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
enum BlockTransactionDetails {
|
|
1630
|
-
accounts
|
|
1631
|
-
full
|
|
1632
|
-
none
|
|
1633
|
-
signatures
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
enum Commitment {
|
|
1637
|
-
confirmed
|
|
1638
|
-
finalized
|
|
1639
|
-
processed
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
type ReturnData {
|
|
1643
|
-
data: Base64EncodedBytes
|
|
1644
|
-
programId: Address
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
type Reward {
|
|
1648
|
-
commission: Int
|
|
1649
|
-
lamports: BigInt
|
|
1650
|
-
postBalance: BigInt
|
|
1651
|
-
pubkey: Address
|
|
1652
|
-
rewardType: String
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
type TokenAmount {
|
|
1656
|
-
amount: String
|
|
1657
|
-
decimals: Int
|
|
1658
|
-
uiAmount: BigInt
|
|
1659
|
-
uiAmountString: String
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
type TokenBalance {
|
|
1663
|
-
accountIndex: Int
|
|
1664
|
-
mint: Account
|
|
1665
|
-
owner: Account
|
|
1666
|
-
programId: Address
|
|
1667
|
-
uiTokenAmount: TokenAmount
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
|
-
enum TransactionEncoding {
|
|
1671
|
-
BASE_58
|
|
1672
|
-
BASE_64
|
|
1673
|
-
PARSED
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
enum TransactionVersion {
|
|
1677
|
-
LEGACY
|
|
1678
|
-
ZERO
|
|
1679
|
-
}
|
|
1680
|
-
`
|
|
1681
|
-
);
|
|
1682
|
-
|
|
1683
1926
|
// src/schema/instruction.ts
|
|
1684
1927
|
var instructionTypeDefs = (
|
|
1685
1928
|
/* GraphQL */
|
|
@@ -2733,28 +2976,20 @@ var rootTypeDefs = (
|
|
|
2733
2976
|
/* GraphQL */
|
|
2734
2977
|
`
|
|
2735
2978
|
type Query {
|
|
2736
|
-
account(
|
|
2737
|
-
address: String!
|
|
2738
|
-
commitment: Commitment
|
|
2739
|
-
dataSlice: DataSlice
|
|
2740
|
-
encoding: AccountEncoding
|
|
2741
|
-
minContextSlot: BigInt
|
|
2742
|
-
): Account
|
|
2979
|
+
account(address: Address!, commitment: Commitment, minContextSlot: Slot): Account
|
|
2743
2980
|
block(
|
|
2744
|
-
slot:
|
|
2981
|
+
slot: Slot!
|
|
2745
2982
|
commitment: Commitment
|
|
2746
2983
|
encoding: TransactionEncoding
|
|
2747
2984
|
transactionDetails: BlockTransactionDetails
|
|
2748
2985
|
): Block
|
|
2749
2986
|
programAccounts(
|
|
2750
|
-
programAddress:
|
|
2987
|
+
programAddress: Address!
|
|
2751
2988
|
commitment: Commitment
|
|
2752
|
-
dataSlice: DataSlice
|
|
2753
|
-
encoding: AccountEncoding
|
|
2754
2989
|
filters: [ProgramAccountsFilter]
|
|
2755
|
-
minContextSlot:
|
|
2990
|
+
minContextSlot: Slot
|
|
2756
2991
|
): [Account]
|
|
2757
|
-
transaction(signature:
|
|
2992
|
+
transaction(signature: Signature!, commitment: Commitment, encoding: TransactionEncoding): Transaction
|
|
2758
2993
|
}
|
|
2759
2994
|
|
|
2760
2995
|
schema {
|
|
@@ -2877,29 +3112,114 @@ var transactionTypeDefs = (
|
|
|
2877
3112
|
`
|
|
2878
3113
|
);
|
|
2879
3114
|
|
|
3115
|
+
// src/schema/types.ts
|
|
3116
|
+
var typeTypeDefs = (
|
|
3117
|
+
/* GraphQL */
|
|
3118
|
+
`
|
|
3119
|
+
enum AccountEncoding {
|
|
3120
|
+
BASE_58
|
|
3121
|
+
BASE_64
|
|
3122
|
+
BASE_64_ZSTD
|
|
3123
|
+
}
|
|
3124
|
+
|
|
3125
|
+
scalar Address
|
|
3126
|
+
|
|
3127
|
+
scalar Base58EncodedBytes
|
|
3128
|
+
|
|
3129
|
+
scalar Base64EncodedBytes
|
|
3130
|
+
|
|
3131
|
+
scalar Base64ZstdEncodedBytes
|
|
3132
|
+
|
|
3133
|
+
scalar BigInt
|
|
3134
|
+
|
|
3135
|
+
enum BlockTransactionDetails {
|
|
3136
|
+
ACCOUNTS
|
|
3137
|
+
FULL
|
|
3138
|
+
NONE
|
|
3139
|
+
SIGNATURES
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
enum Commitment {
|
|
3143
|
+
CONFIRMED
|
|
3144
|
+
FINALIZED
|
|
3145
|
+
PROCESSED
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
input DataSlice {
|
|
3149
|
+
offset: Int!
|
|
3150
|
+
length: Int!
|
|
3151
|
+
}
|
|
3152
|
+
|
|
3153
|
+
input ProgramAccountsFilter {
|
|
3154
|
+
bytes: BigInt
|
|
3155
|
+
dataSize: BigInt
|
|
3156
|
+
encoding: AccountEncoding
|
|
3157
|
+
offset: BigInt
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3160
|
+
type ReturnData {
|
|
3161
|
+
data: Base64EncodedBytes
|
|
3162
|
+
programId: Address
|
|
3163
|
+
}
|
|
3164
|
+
|
|
3165
|
+
type Reward {
|
|
3166
|
+
commission: Int
|
|
3167
|
+
lamports: BigInt
|
|
3168
|
+
postBalance: BigInt
|
|
3169
|
+
pubkey: Address
|
|
3170
|
+
rewardType: String
|
|
3171
|
+
}
|
|
3172
|
+
|
|
3173
|
+
scalar Signature
|
|
3174
|
+
|
|
3175
|
+
scalar Slot
|
|
3176
|
+
|
|
3177
|
+
type TokenAmount {
|
|
3178
|
+
amount: String
|
|
3179
|
+
decimals: Int
|
|
3180
|
+
uiAmount: BigInt
|
|
3181
|
+
uiAmountString: String
|
|
3182
|
+
}
|
|
3183
|
+
|
|
3184
|
+
type TokenBalance {
|
|
3185
|
+
accountIndex: Int
|
|
3186
|
+
mint: Account
|
|
3187
|
+
owner: Account
|
|
3188
|
+
programId: Address
|
|
3189
|
+
uiTokenAmount: TokenAmount
|
|
3190
|
+
}
|
|
3191
|
+
|
|
3192
|
+
enum TransactionEncoding {
|
|
3193
|
+
BASE_58
|
|
3194
|
+
BASE_64
|
|
3195
|
+
PARSED
|
|
3196
|
+
}
|
|
3197
|
+
|
|
3198
|
+
enum TransactionVersion {
|
|
3199
|
+
LEGACY
|
|
3200
|
+
ZERO
|
|
3201
|
+
}
|
|
3202
|
+
`
|
|
3203
|
+
);
|
|
3204
|
+
|
|
2880
3205
|
// src/schema/index.ts
|
|
2881
3206
|
function createSolanaGraphQLTypeDefs() {
|
|
2882
|
-
return [
|
|
2883
|
-
accountTypeDefs,
|
|
2884
|
-
blockTypeDefs,
|
|
2885
|
-
commonTypeDefs,
|
|
2886
|
-
inputTypeDefs,
|
|
2887
|
-
instructionTypeDefs,
|
|
2888
|
-
rootTypeDefs,
|
|
2889
|
-
scalarTypeDefs,
|
|
2890
|
-
transactionTypeDefs
|
|
2891
|
-
];
|
|
3207
|
+
return [accountTypeDefs, blockTypeDefs, instructionTypeDefs, rootTypeDefs, typeTypeDefs, transactionTypeDefs];
|
|
2892
3208
|
}
|
|
2893
3209
|
|
|
2894
3210
|
// src/index.ts
|
|
2895
|
-
function createRpcGraphQL(rpc) {
|
|
3211
|
+
function createRpcGraphQL(rpc, config) {
|
|
3212
|
+
const rpcGraphQLConfig = {
|
|
3213
|
+
maxDataSliceByteRange: config?.maxDataSliceByteRange ?? 200,
|
|
3214
|
+
maxMultipleAccountsBatchSize: config?.maxMultipleAccountsBatchSize ?? 100
|
|
3215
|
+
};
|
|
2896
3216
|
const schema = makeExecutableSchema({
|
|
2897
3217
|
resolvers: createSolanaGraphQLResolvers(),
|
|
2898
3218
|
typeDefs: createSolanaGraphQLTypeDefs()
|
|
2899
3219
|
});
|
|
2900
3220
|
return {
|
|
2901
3221
|
async query(source, variableValues) {
|
|
2902
|
-
const contextValue = createSolanaGraphQLContext(rpc);
|
|
3222
|
+
const contextValue = createSolanaGraphQLContext(rpc, rpcGraphQLConfig);
|
|
2903
3223
|
return graphql({
|
|
2904
3224
|
contextValue,
|
|
2905
3225
|
schema,
|