@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.
@@ -40,7 +40,19 @@ function createGraphQLCache() {
40
40
  }
41
41
 
42
42
  // src/context.ts
43
- async function resolveAccount({ address, encoding = "jsonParsed", ...config }, cache, rpc) {
43
+ async function resolveAccount({ address, encoding = "jsonParsed", ...config }, cache, rpc, info) {
44
+ if (info && info.fieldNodes[0].selectionSet) {
45
+ const selectionSet = info.fieldNodes[0].selectionSet;
46
+ const requestedFields = selectionSet.selections.map((field) => {
47
+ if (field.kind === "Field") {
48
+ return field.name.value;
49
+ }
50
+ return null;
51
+ });
52
+ if (requestedFields && requestedFields.length === 1 && requestedFields[0] === "address") {
53
+ return { address };
54
+ }
55
+ }
44
56
  const requestConfig = { encoding, ...config };
45
57
  const cached = cache.get(address, requestConfig);
46
58
  if (cached !== null) {
@@ -50,11 +62,14 @@ async function resolveAccount({ address, encoding = "jsonParsed", ...config }, c
50
62
  throw e;
51
63
  });
52
64
  if (account === null) {
53
- return null;
65
+ return {
66
+ address
67
+ };
54
68
  }
55
69
  const [data, responseEncoding] = Array.isArray(account.data) ? encoding === "jsonParsed" ? [account.data[0], "base64"] : [account.data[0], encoding] : [account.data, "jsonParsed"];
56
70
  const queryResponse = {
57
71
  ...account,
72
+ address,
58
73
  data,
59
74
  encoding: responseEncoding
60
75
  };
@@ -88,13 +103,14 @@ async function resolveProgramAccounts({ programAddress, encoding = "jsonParsed",
88
103
  }).catch((e) => {
89
104
  throw e;
90
105
  });
91
- const queryResponse = programAccounts.map((programAccount2) => {
92
- const [data, responseEncoding] = Array.isArray(programAccount2.account.data) ? encoding === "jsonParsed" ? [programAccount2.account.data[0], "base64"] : [programAccount2.account.data[0], encoding] : [programAccount2.account.data, "jsonParsed"];
93
- const pubkey = programAccount2.pubkey;
94
- const account = { ...programAccount2.account, data, encoding: responseEncoding };
106
+ const queryResponse = programAccounts.map((programAccount) => {
107
+ const [data, responseEncoding] = Array.isArray(programAccount.account.data) ? encoding === "jsonParsed" ? [programAccount.account.data[0], "base64"] : [programAccount.account.data[0], encoding] : [programAccount.account.data, "jsonParsed"];
108
+ const pubkey = programAccount.pubkey;
95
109
  return {
96
- account,
97
- pubkey
110
+ ...programAccount.account,
111
+ address: pubkey,
112
+ data,
113
+ encoding: responseEncoding
98
114
  };
99
115
  });
100
116
  cache.insert(programAddress, requestConfig, queryResponse);
@@ -129,8 +145,8 @@ function createSolanaGraphQLContext(rpc) {
129
145
  const cache = createGraphQLCache();
130
146
  return {
131
147
  cache,
132
- resolveAccount(args) {
133
- return resolveAccount(args, this.cache, this.rpc);
148
+ resolveAccount(args, info) {
149
+ return resolveAccount(args, this.cache, this.rpc, info);
134
150
  },
135
151
  resolveBlock(args) {
136
152
  return resolveBlock(args, this.cache, this.rpc);
@@ -272,7 +288,7 @@ var dataSliceInputType = () => {
272
288
  length: number(),
273
289
  offset: number()
274
290
  },
275
- name: "DataSliceConfig"
291
+ name: "DataSlice"
276
292
  });
277
293
  return memoisedDataSliceInputType;
278
294
  };
@@ -347,6 +363,7 @@ var memoisedAccountInterfaceFields;
347
363
  var accountInterfaceFields = () => {
348
364
  if (!memoisedAccountInterfaceFields) {
349
365
  memoisedAccountInterfaceFields = {
366
+ address: string(),
350
367
  encoding: string(),
351
368
  executable: boolean(),
352
369
  lamports: bigint(),
@@ -406,6 +423,7 @@ var accountType = (name, description, data) => new graphql.GraphQLObjectType({
406
423
  fields: {
407
424
  ...accountInterfaceFields(),
408
425
  data,
426
+ // Nested Account interface
409
427
  owner: {
410
428
  args: {
411
429
  commitment: type(commitmentInputType()),
@@ -413,7 +431,7 @@ var accountType = (name, description, data) => new graphql.GraphQLObjectType({
413
431
  encoding: type(accountEncodingInputType()),
414
432
  minContextSlot: bigint()
415
433
  },
416
- resolve: (parent, args, context) => context.resolveAccount({ ...args, address: parent.owner }),
434
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.owner }, info),
417
435
  type: accountInterface()
418
436
  }
419
437
  },
@@ -457,7 +475,18 @@ var accountNonceAccount = () => {
457
475
  "NonceAccount",
458
476
  "A nonce account",
459
477
  accountDataJsonParsed("Nonce", {
460
- authority: string(),
478
+ // Nested Account interface
479
+ authority: {
480
+ args: {
481
+ commitment: type(commitmentInputType()),
482
+ dataSlice: type(dataSliceInputType()),
483
+ encoding: type(accountEncodingInputType()),
484
+ minContextSlot: bigint()
485
+ },
486
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
487
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authority }, info),
488
+ type: accountInterface()
489
+ },
461
490
  blockhash: string(),
462
491
  feeCalculator: object("NonceFeeCalculator", {
463
492
  lamportsPerSignature: string()
@@ -474,7 +503,18 @@ var accountLookupTable = () => {
474
503
  "An address lookup table account",
475
504
  accountDataJsonParsed("LookupTable", {
476
505
  addresses: list(string()),
477
- authority: string(),
506
+ // Nested Account interface
507
+ authority: {
508
+ args: {
509
+ commitment: type(commitmentInputType()),
510
+ dataSlice: type(dataSliceInputType()),
511
+ encoding: type(accountEncodingInputType()),
512
+ minContextSlot: bigint()
513
+ },
514
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
515
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authority }, info),
516
+ type: accountInterface()
517
+ },
478
518
  deactivationSlot: string(),
479
519
  lastExtendedSlot: string(),
480
520
  lastExtendedSlotStartIndex: number()
@@ -492,7 +532,18 @@ var accountMint = () => {
492
532
  decimals: number(),
493
533
  freezeAuthority: string(),
494
534
  isInitialized: boolean(),
495
- mintAuthority: string(),
535
+ // Nested Account interface
536
+ mintAuthority: {
537
+ args: {
538
+ commitment: type(commitmentInputType()),
539
+ dataSlice: type(dataSliceInputType()),
540
+ encoding: type(accountEncodingInputType()),
541
+ minContextSlot: bigint()
542
+ },
543
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
544
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.mintAuthority }, info),
545
+ type: accountInterface()
546
+ },
496
547
  supply: string()
497
548
  })
498
549
  );
@@ -507,7 +558,18 @@ var accountTokenAccount = () => {
507
558
  accountDataJsonParsed("TokenAccount", {
508
559
  isNative: boolean(),
509
560
  mint: string(),
510
- owner: string(),
561
+ // Nested Account interface
562
+ owner: {
563
+ args: {
564
+ commitment: type(commitmentInputType()),
565
+ dataSlice: type(dataSliceInputType()),
566
+ encoding: type(accountEncodingInputType()),
567
+ minContextSlot: bigint()
568
+ },
569
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
570
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.owner }, info),
571
+ type: accountInterface()
572
+ },
511
573
  state: string(),
512
574
  tokenAmount: type(tokenAmountType())
513
575
  })
@@ -523,11 +585,44 @@ var accountStakeAccount = () => {
523
585
  accountDataJsonParsed("Stake", {
524
586
  meta: object("StakeMeta", {
525
587
  authorized: object("StakeMetaAuthorized", {
526
- staker: string(),
527
- withdrawer: string()
588
+ // Nested Account interface
589
+ staker: {
590
+ args: {
591
+ commitment: type(commitmentInputType()),
592
+ dataSlice: type(dataSliceInputType()),
593
+ encoding: type(accountEncodingInputType()),
594
+ minContextSlot: bigint()
595
+ },
596
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
597
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.staker }, info),
598
+ type: accountInterface()
599
+ },
600
+ // Nested Account interface
601
+ withdrawer: {
602
+ args: {
603
+ commitment: type(commitmentInputType()),
604
+ dataSlice: type(dataSliceInputType()),
605
+ encoding: type(accountEncodingInputType()),
606
+ minContextSlot: bigint()
607
+ },
608
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
609
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.withdrawer }, info),
610
+ type: accountInterface()
611
+ }
528
612
  }),
529
613
  lockup: object("StakeMetaLockup", {
530
- custodian: string(),
614
+ // Nested Account interface
615
+ custodian: {
616
+ args: {
617
+ commitment: type(commitmentInputType()),
618
+ dataSlice: type(dataSliceInputType()),
619
+ encoding: type(accountEncodingInputType()),
620
+ minContextSlot: bigint()
621
+ },
622
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
623
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.custodian }, info),
624
+ type: accountInterface()
625
+ },
531
626
  epoch: bigint(),
532
627
  unixTimestamp: bigint()
533
628
  }),
@@ -539,7 +634,18 @@ var accountStakeAccount = () => {
539
634
  activationEpoch: bigint(),
540
635
  deactivationEpoch: bigint(),
541
636
  stake: string(),
542
- voter: string(),
637
+ // Nested Account interface
638
+ voter: {
639
+ args: {
640
+ commitment: type(commitmentInputType()),
641
+ dataSlice: type(dataSliceInputType()),
642
+ encoding: type(accountEncodingInputType()),
643
+ minContextSlot: bigint()
644
+ },
645
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
646
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.voter }, info),
647
+ type: accountInterface()
648
+ },
543
649
  warmupCooldownRate: number()
544
650
  })
545
651
  })
@@ -556,11 +662,33 @@ var accountVoteAccount = () => {
556
662
  accountDataJsonParsed("Vote", {
557
663
  authorizedVoters: list(
558
664
  object("VoteAuthorizedVoter", {
559
- authorizedVoter: string(),
665
+ // Nested Account interface
666
+ authorizedVoter: {
667
+ args: {
668
+ commitment: type(commitmentInputType()),
669
+ dataSlice: type(dataSliceInputType()),
670
+ encoding: type(accountEncodingInputType()),
671
+ minContextSlot: bigint()
672
+ },
673
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
674
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authorizedVoter }, info),
675
+ type: accountInterface()
676
+ },
560
677
  epoch: bigint()
561
678
  })
562
679
  ),
563
- authorizedWithdrawer: string(),
680
+ // Nested Account interface
681
+ authorizedWithdrawer: {
682
+ args: {
683
+ commitment: type(commitmentInputType()),
684
+ dataSlice: type(dataSliceInputType()),
685
+ encoding: type(accountEncodingInputType()),
686
+ minContextSlot: bigint()
687
+ },
688
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
689
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authorizedWithdrawer }, info),
690
+ type: accountInterface()
691
+ },
564
692
  commission: number(),
565
693
  epochCredits: list(
566
694
  object("VoteEpochCredits", {
@@ -573,7 +701,18 @@ var accountVoteAccount = () => {
573
701
  slot: bigint(),
574
702
  timestamp: bigint()
575
703
  }),
576
- nodePubkey: string(),
704
+ // Nested Account interface
705
+ node: {
706
+ args: {
707
+ commitment: type(commitmentInputType()),
708
+ dataSlice: type(dataSliceInputType()),
709
+ encoding: type(accountEncodingInputType()),
710
+ minContextSlot: bigint()
711
+ },
712
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
713
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.nodePubkey }, info),
714
+ type: accountInterface()
715
+ },
577
716
  priorVoters: list(string()),
578
717
  rootSlot: bigint(),
579
718
  votes: list(
@@ -613,7 +752,8 @@ var accountQuery = () => ({
613
752
  encoding: type(accountEncodingInputType()),
614
753
  minContextSlot: bigint()
615
754
  },
616
- resolve: (_parent, args, context) => context.resolveAccount(args),
755
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
756
+ resolve: (_parent, args, context, info) => context.resolveAccount(args, info),
617
757
  type: accountInterface()
618
758
  }
619
759
  });
@@ -2142,15 +2282,6 @@ var blockQuery = () => ({
2142
2282
  type: blockInterface()
2143
2283
  }
2144
2284
  });
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
2285
  var programAccountsQuery = () => ({
2155
2286
  programAccounts: {
2156
2287
  args: {
@@ -2163,7 +2294,7 @@ var programAccountsQuery = () => ({
2163
2294
  withContext: string()
2164
2295
  },
2165
2296
  resolve: (_parent, args, context) => context.resolveProgramAccounts(args),
2166
- type: new graphql.GraphQLList(programAccount())
2297
+ type: new graphql.GraphQLList(accountInterface())
2167
2298
  }
2168
2299
  });
2169
2300