@solana/rpc-graphql 2.0.0-experimental.8c5ac55 → 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) {
@@ -87,13 +99,14 @@ async function resolveProgramAccounts({ programAddress, encoding = "jsonParsed",
87
99
  }).catch((e) => {
88
100
  throw e;
89
101
  });
90
- const queryResponse = programAccounts.map((programAccount2) => {
91
- const [data, responseEncoding] = Array.isArray(programAccount2.account.data) ? encoding === "jsonParsed" ? [programAccount2.account.data[0], "base64"] : [programAccount2.account.data[0], encoding] : [programAccount2.account.data, "jsonParsed"];
92
- const pubkey = programAccount2.pubkey;
93
- 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;
94
105
  return {
95
- account,
96
- pubkey
106
+ ...programAccount.account,
107
+ address: pubkey,
108
+ data,
109
+ encoding: responseEncoding
97
110
  };
98
111
  });
99
112
  cache.insert(programAddress, requestConfig, queryResponse);
@@ -128,8 +141,8 @@ function createSolanaGraphQLContext(rpc) {
128
141
  const cache = createGraphQLCache();
129
142
  return {
130
143
  cache,
131
- resolveAccount(args) {
132
- return resolveAccount(args, this.cache, this.rpc);
144
+ resolveAccount(args, info) {
145
+ return resolveAccount(args, this.cache, this.rpc, info);
133
146
  },
134
147
  resolveBlock(args) {
135
148
  return resolveBlock(args, this.cache, this.rpc);
@@ -271,7 +284,7 @@ var dataSliceInputType = () => {
271
284
  length: number(),
272
285
  offset: number()
273
286
  },
274
- name: "DataSliceConfig"
287
+ name: "DataSlice"
275
288
  });
276
289
  return memoisedDataSliceInputType;
277
290
  };
@@ -406,6 +419,7 @@ var accountType = (name, description, data) => new graphql.GraphQLObjectType({
406
419
  fields: {
407
420
  ...accountInterfaceFields(),
408
421
  data,
422
+ // Nested Account interface
409
423
  owner: {
410
424
  args: {
411
425
  commitment: type(commitmentInputType()),
@@ -413,7 +427,7 @@ var accountType = (name, description, data) => new graphql.GraphQLObjectType({
413
427
  encoding: type(accountEncodingInputType()),
414
428
  minContextSlot: bigint()
415
429
  },
416
- resolve: (parent, args, context) => context.resolveAccount({ ...args, address: parent.owner }),
430
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.owner }, info),
417
431
  type: accountInterface()
418
432
  }
419
433
  },
@@ -457,7 +471,18 @@ var accountNonceAccount = () => {
457
471
  "NonceAccount",
458
472
  "A nonce account",
459
473
  accountDataJsonParsed("Nonce", {
460
- 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
+ },
461
486
  blockhash: string(),
462
487
  feeCalculator: object("NonceFeeCalculator", {
463
488
  lamportsPerSignature: string()
@@ -474,7 +499,18 @@ var accountLookupTable = () => {
474
499
  "An address lookup table account",
475
500
  accountDataJsonParsed("LookupTable", {
476
501
  addresses: list(string()),
477
- 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
+ },
478
514
  deactivationSlot: string(),
479
515
  lastExtendedSlot: string(),
480
516
  lastExtendedSlotStartIndex: number()
@@ -492,7 +528,18 @@ var accountMint = () => {
492
528
  decimals: number(),
493
529
  freezeAuthority: string(),
494
530
  isInitialized: boolean(),
495
- 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
+ },
496
543
  supply: string()
497
544
  })
498
545
  );
@@ -507,7 +554,18 @@ var accountTokenAccount = () => {
507
554
  accountDataJsonParsed("TokenAccount", {
508
555
  isNative: boolean(),
509
556
  mint: string(),
510
- 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
+ },
511
569
  state: string(),
512
570
  tokenAmount: type(tokenAmountType())
513
571
  })
@@ -523,11 +581,44 @@ var accountStakeAccount = () => {
523
581
  accountDataJsonParsed("Stake", {
524
582
  meta: object("StakeMeta", {
525
583
  authorized: object("StakeMetaAuthorized", {
526
- staker: string(),
527
- 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
+ }
528
608
  }),
529
609
  lockup: object("StakeMetaLockup", {
530
- 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
+ },
531
622
  epoch: bigint(),
532
623
  unixTimestamp: bigint()
533
624
  }),
@@ -539,7 +630,18 @@ var accountStakeAccount = () => {
539
630
  activationEpoch: bigint(),
540
631
  deactivationEpoch: bigint(),
541
632
  stake: string(),
542
- 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
+ },
543
645
  warmupCooldownRate: number()
544
646
  })
545
647
  })
@@ -556,11 +658,33 @@ var accountVoteAccount = () => {
556
658
  accountDataJsonParsed("Vote", {
557
659
  authorizedVoters: list(
558
660
  object("VoteAuthorizedVoter", {
559
- 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
+ },
560
673
  epoch: bigint()
561
674
  })
562
675
  ),
563
- 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
+ },
564
688
  commission: number(),
565
689
  epochCredits: list(
566
690
  object("VoteEpochCredits", {
@@ -573,7 +697,18 @@ var accountVoteAccount = () => {
573
697
  slot: bigint(),
574
698
  timestamp: bigint()
575
699
  }),
576
- 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
+ },
577
712
  priorVoters: list(string()),
578
713
  rootSlot: bigint(),
579
714
  votes: list(
@@ -613,7 +748,8 @@ var accountQuery = () => ({
613
748
  encoding: type(accountEncodingInputType()),
614
749
  minContextSlot: bigint()
615
750
  },
616
- 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),
617
753
  type: accountInterface()
618
754
  }
619
755
  });
@@ -2142,15 +2278,6 @@ var blockQuery = () => ({
2142
2278
  type: blockInterface()
2143
2279
  }
2144
2280
  });
2145
- var programAccount = () => new graphql.GraphQLObjectType({
2146
- fields: {
2147
- account: type(accountInterface()),
2148
- pubkey: string()
2149
- },
2150
- name: "ProgramAccount"
2151
- });
2152
-
2153
- // src/schema/program-accounts/query.ts
2154
2281
  var programAccountsQuery = () => ({
2155
2282
  programAccounts: {
2156
2283
  args: {
@@ -2163,7 +2290,7 @@ var programAccountsQuery = () => ({
2163
2290
  withContext: string()
2164
2291
  },
2165
2292
  resolve: (_parent, args, context) => context.resolveProgramAccounts(args),
2166
- type: new graphql.GraphQLList(programAccount())
2293
+ type: new graphql.GraphQLList(accountInterface())
2167
2294
  }
2168
2295
  });
2169
2296