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