@solana/rpc-graphql 2.0.0-experimental.99a64e9 → 2.0.0-experimental.9c8a30e

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.
@@ -36,7 +36,19 @@ function createGraphQLCache() {
36
36
  }
37
37
 
38
38
  // src/context.ts
39
- async function resolveAccount({ address, encoding = "jsonParsed", ...config }, cache, rpc) {
39
+ async function resolveAccount({ address, encoding = "jsonParsed", ...config }, cache, rpc, info) {
40
+ if (info && info.fieldNodes[0].selectionSet) {
41
+ const selectionSet = info.fieldNodes[0].selectionSet;
42
+ const requestedFields = selectionSet.selections.map((field) => {
43
+ if (field.kind === "Field") {
44
+ return field.name.value;
45
+ }
46
+ return null;
47
+ });
48
+ if (requestedFields && requestedFields.length === 1 && requestedFields[0] === "address") {
49
+ return { address };
50
+ }
51
+ }
40
52
  const requestConfig = { encoding, ...config };
41
53
  const cached = cache.get(address, requestConfig);
42
54
  if (cached !== null) {
@@ -46,11 +58,14 @@ async function resolveAccount({ address, encoding = "jsonParsed", ...config }, c
46
58
  throw e;
47
59
  });
48
60
  if (account === null) {
49
- return null;
61
+ return {
62
+ address
63
+ };
50
64
  }
51
65
  const [data, responseEncoding] = Array.isArray(account.data) ? encoding === "jsonParsed" ? [account.data[0], "base64"] : [account.data[0], encoding] : [account.data, "jsonParsed"];
52
66
  const queryResponse = {
53
67
  ...account,
68
+ address,
54
69
  data,
55
70
  encoding: responseEncoding
56
71
  };
@@ -84,13 +99,14 @@ async function resolveProgramAccounts({ programAddress, encoding = "jsonParsed",
84
99
  }).catch((e) => {
85
100
  throw e;
86
101
  });
87
- const queryResponse = programAccounts.map((programAccount2) => {
88
- const [data, responseEncoding] = Array.isArray(programAccount2.account.data) ? encoding === "jsonParsed" ? [programAccount2.account.data[0], "base64"] : [programAccount2.account.data[0], encoding] : [programAccount2.account.data, "jsonParsed"];
89
- const pubkey = programAccount2.pubkey;
90
- const account = { ...programAccount2.account, data, encoding: responseEncoding };
102
+ const queryResponse = programAccounts.map((programAccount) => {
103
+ const [data, responseEncoding] = Array.isArray(programAccount.account.data) ? encoding === "jsonParsed" ? [programAccount.account.data[0], "base64"] : [programAccount.account.data[0], encoding] : [programAccount.account.data, "jsonParsed"];
104
+ const pubkey = programAccount.pubkey;
91
105
  return {
92
- account,
93
- pubkey
106
+ ...programAccount.account,
107
+ address: pubkey,
108
+ data,
109
+ encoding: responseEncoding
94
110
  };
95
111
  });
96
112
  cache.insert(programAddress, requestConfig, queryResponse);
@@ -125,8 +141,8 @@ function createSolanaGraphQLContext(rpc) {
125
141
  const cache = createGraphQLCache();
126
142
  return {
127
143
  cache,
128
- resolveAccount(args) {
129
- return resolveAccount(args, this.cache, this.rpc);
144
+ resolveAccount(args, info) {
145
+ return resolveAccount(args, this.cache, this.rpc, info);
130
146
  },
131
147
  resolveBlock(args) {
132
148
  return resolveBlock(args, this.cache, this.rpc);
@@ -268,7 +284,7 @@ var dataSliceInputType = () => {
268
284
  length: number(),
269
285
  offset: number()
270
286
  },
271
- name: "DataSliceConfig"
287
+ name: "DataSlice"
272
288
  });
273
289
  return memoisedDataSliceInputType;
274
290
  };
@@ -343,6 +359,7 @@ var memoisedAccountInterfaceFields;
343
359
  var accountInterfaceFields = () => {
344
360
  if (!memoisedAccountInterfaceFields) {
345
361
  memoisedAccountInterfaceFields = {
362
+ address: string(),
346
363
  encoding: string(),
347
364
  executable: boolean(),
348
365
  lamports: bigint(),
@@ -402,6 +419,7 @@ var accountType = (name, description, data) => new graphql.GraphQLObjectType({
402
419
  fields: {
403
420
  ...accountInterfaceFields(),
404
421
  data,
422
+ // Nested Account interface
405
423
  owner: {
406
424
  args: {
407
425
  commitment: type(commitmentInputType()),
@@ -409,7 +427,7 @@ var accountType = (name, description, data) => new graphql.GraphQLObjectType({
409
427
  encoding: type(accountEncodingInputType()),
410
428
  minContextSlot: bigint()
411
429
  },
412
- resolve: (parent, args, context) => context.resolveAccount({ ...args, address: parent.owner }),
430
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.owner }, info),
413
431
  type: accountInterface()
414
432
  }
415
433
  },
@@ -453,7 +471,18 @@ var accountNonceAccount = () => {
453
471
  "NonceAccount",
454
472
  "A nonce account",
455
473
  accountDataJsonParsed("Nonce", {
456
- authority: string(),
474
+ // Nested Account interface
475
+ authority: {
476
+ args: {
477
+ commitment: type(commitmentInputType()),
478
+ dataSlice: type(dataSliceInputType()),
479
+ encoding: type(accountEncodingInputType()),
480
+ minContextSlot: bigint()
481
+ },
482
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
483
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authority }, info),
484
+ type: accountInterface()
485
+ },
457
486
  blockhash: string(),
458
487
  feeCalculator: object("NonceFeeCalculator", {
459
488
  lamportsPerSignature: string()
@@ -470,7 +499,18 @@ var accountLookupTable = () => {
470
499
  "An address lookup table account",
471
500
  accountDataJsonParsed("LookupTable", {
472
501
  addresses: list(string()),
473
- authority: string(),
502
+ // Nested Account interface
503
+ authority: {
504
+ args: {
505
+ commitment: type(commitmentInputType()),
506
+ dataSlice: type(dataSliceInputType()),
507
+ encoding: type(accountEncodingInputType()),
508
+ minContextSlot: bigint()
509
+ },
510
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
511
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authority }, info),
512
+ type: accountInterface()
513
+ },
474
514
  deactivationSlot: string(),
475
515
  lastExtendedSlot: string(),
476
516
  lastExtendedSlotStartIndex: number()
@@ -488,7 +528,18 @@ var accountMint = () => {
488
528
  decimals: number(),
489
529
  freezeAuthority: string(),
490
530
  isInitialized: boolean(),
491
- mintAuthority: string(),
531
+ // Nested Account interface
532
+ mintAuthority: {
533
+ args: {
534
+ commitment: type(commitmentInputType()),
535
+ dataSlice: type(dataSliceInputType()),
536
+ encoding: type(accountEncodingInputType()),
537
+ minContextSlot: bigint()
538
+ },
539
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
540
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.mintAuthority }, info),
541
+ type: accountInterface()
542
+ },
492
543
  supply: string()
493
544
  })
494
545
  );
@@ -503,7 +554,18 @@ var accountTokenAccount = () => {
503
554
  accountDataJsonParsed("TokenAccount", {
504
555
  isNative: boolean(),
505
556
  mint: string(),
506
- owner: string(),
557
+ // Nested Account interface
558
+ owner: {
559
+ args: {
560
+ commitment: type(commitmentInputType()),
561
+ dataSlice: type(dataSliceInputType()),
562
+ encoding: type(accountEncodingInputType()),
563
+ minContextSlot: bigint()
564
+ },
565
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
566
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.owner }, info),
567
+ type: accountInterface()
568
+ },
507
569
  state: string(),
508
570
  tokenAmount: type(tokenAmountType())
509
571
  })
@@ -519,11 +581,44 @@ var accountStakeAccount = () => {
519
581
  accountDataJsonParsed("Stake", {
520
582
  meta: object("StakeMeta", {
521
583
  authorized: object("StakeMetaAuthorized", {
522
- staker: string(),
523
- withdrawer: string()
584
+ // Nested Account interface
585
+ staker: {
586
+ args: {
587
+ commitment: type(commitmentInputType()),
588
+ dataSlice: type(dataSliceInputType()),
589
+ encoding: type(accountEncodingInputType()),
590
+ minContextSlot: bigint()
591
+ },
592
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
593
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.staker }, info),
594
+ type: accountInterface()
595
+ },
596
+ // Nested Account interface
597
+ withdrawer: {
598
+ args: {
599
+ commitment: type(commitmentInputType()),
600
+ dataSlice: type(dataSliceInputType()),
601
+ encoding: type(accountEncodingInputType()),
602
+ minContextSlot: bigint()
603
+ },
604
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
605
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.withdrawer }, info),
606
+ type: accountInterface()
607
+ }
524
608
  }),
525
609
  lockup: object("StakeMetaLockup", {
526
- custodian: string(),
610
+ // Nested Account interface
611
+ custodian: {
612
+ args: {
613
+ commitment: type(commitmentInputType()),
614
+ dataSlice: type(dataSliceInputType()),
615
+ encoding: type(accountEncodingInputType()),
616
+ minContextSlot: bigint()
617
+ },
618
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
619
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.custodian }, info),
620
+ type: accountInterface()
621
+ },
527
622
  epoch: bigint(),
528
623
  unixTimestamp: bigint()
529
624
  }),
@@ -535,7 +630,18 @@ var accountStakeAccount = () => {
535
630
  activationEpoch: bigint(),
536
631
  deactivationEpoch: bigint(),
537
632
  stake: string(),
538
- voter: string(),
633
+ // Nested Account interface
634
+ voter: {
635
+ args: {
636
+ commitment: type(commitmentInputType()),
637
+ dataSlice: type(dataSliceInputType()),
638
+ encoding: type(accountEncodingInputType()),
639
+ minContextSlot: bigint()
640
+ },
641
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
642
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.voter }, info),
643
+ type: accountInterface()
644
+ },
539
645
  warmupCooldownRate: number()
540
646
  })
541
647
  })
@@ -552,11 +658,33 @@ var accountVoteAccount = () => {
552
658
  accountDataJsonParsed("Vote", {
553
659
  authorizedVoters: list(
554
660
  object("VoteAuthorizedVoter", {
555
- authorizedVoter: string(),
661
+ // Nested Account interface
662
+ authorizedVoter: {
663
+ args: {
664
+ commitment: type(commitmentInputType()),
665
+ dataSlice: type(dataSliceInputType()),
666
+ encoding: type(accountEncodingInputType()),
667
+ minContextSlot: bigint()
668
+ },
669
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
670
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authorizedVoter }, info),
671
+ type: accountInterface()
672
+ },
556
673
  epoch: bigint()
557
674
  })
558
675
  ),
559
- authorizedWithdrawer: string(),
676
+ // Nested Account interface
677
+ authorizedWithdrawer: {
678
+ args: {
679
+ commitment: type(commitmentInputType()),
680
+ dataSlice: type(dataSliceInputType()),
681
+ encoding: type(accountEncodingInputType()),
682
+ minContextSlot: bigint()
683
+ },
684
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
685
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authorizedWithdrawer }, info),
686
+ type: accountInterface()
687
+ },
560
688
  commission: number(),
561
689
  epochCredits: list(
562
690
  object("VoteEpochCredits", {
@@ -569,7 +697,18 @@ var accountVoteAccount = () => {
569
697
  slot: bigint(),
570
698
  timestamp: bigint()
571
699
  }),
572
- nodePubkey: string(),
700
+ // Nested Account interface
701
+ node: {
702
+ args: {
703
+ commitment: type(commitmentInputType()),
704
+ dataSlice: type(dataSliceInputType()),
705
+ encoding: type(accountEncodingInputType()),
706
+ minContextSlot: bigint()
707
+ },
708
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
709
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.nodePubkey }, info),
710
+ type: accountInterface()
711
+ },
573
712
  priorVoters: list(string()),
574
713
  rootSlot: bigint(),
575
714
  votes: list(
@@ -609,7 +748,8 @@ var accountQuery = () => ({
609
748
  encoding: type(accountEncodingInputType()),
610
749
  minContextSlot: bigint()
611
750
  },
612
- resolve: (_parent, args, context) => context.resolveAccount(args),
751
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
752
+ resolve: (_parent, args, context, info) => context.resolveAccount(args, info),
613
753
  type: accountInterface()
614
754
  }
615
755
  });
@@ -2138,15 +2278,6 @@ var blockQuery = () => ({
2138
2278
  type: blockInterface()
2139
2279
  }
2140
2280
  });
2141
- var programAccount = () => new graphql.GraphQLObjectType({
2142
- fields: {
2143
- account: type(accountInterface()),
2144
- pubkey: string()
2145
- },
2146
- name: "ProgramAccount"
2147
- });
2148
-
2149
- // src/schema/program-accounts/query.ts
2150
2281
  var programAccountsQuery = () => ({
2151
2282
  programAccounts: {
2152
2283
  args: {
@@ -2159,7 +2290,7 @@ var programAccountsQuery = () => ({
2159
2290
  withContext: string()
2160
2291
  },
2161
2292
  resolve: (_parent, args, context) => context.resolveProgramAccounts(args),
2162
- type: new graphql.GraphQLList(programAccount())
2293
+ type: new graphql.GraphQLList(accountInterface())
2163
2294
  }
2164
2295
  });
2165
2296