@solana/rpc-graphql 2.0.0-experimental.fc4e943 → 2.0.0-experimental.fd11bd1

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.
Files changed (35) hide show
  1. package/dist/index.browser.cjs +156 -19
  2. package/dist/index.browser.cjs.map +1 -1
  3. package/dist/index.browser.js +156 -17
  4. package/dist/index.browser.js.map +1 -1
  5. package/dist/index.native.js +156 -17
  6. package/dist/index.native.js.map +1 -1
  7. package/dist/index.node.cjs +156 -19
  8. package/dist/index.node.cjs.map +1 -1
  9. package/dist/index.node.js +156 -17
  10. package/dist/index.node.js.map +1 -1
  11. package/dist/types/cache.d.ts.map +1 -0
  12. package/dist/types/context.d.ts +3 -2
  13. package/dist/types/context.d.ts.map +1 -0
  14. package/dist/types/index.d.ts.map +1 -0
  15. package/dist/types/rpc.d.ts.map +1 -0
  16. package/dist/types/schema/account/index.d.ts.map +1 -0
  17. package/dist/types/schema/account/query.d.ts +2 -2
  18. package/dist/types/schema/account/query.d.ts.map +1 -0
  19. package/dist/types/schema/account/types.d.ts.map +1 -0
  20. package/dist/types/schema/block/index.d.ts.map +1 -0
  21. package/dist/types/schema/block/query.d.ts +1 -1
  22. package/dist/types/schema/block/query.d.ts.map +1 -0
  23. package/dist/types/schema/block/types.d.ts.map +1 -0
  24. package/dist/types/schema/inputs.d.ts.map +1 -0
  25. package/dist/types/schema/picks.d.ts.map +1 -0
  26. package/dist/types/schema/program-accounts/index.d.ts.map +1 -0
  27. package/dist/types/schema/program-accounts/query.d.ts +1 -1
  28. package/dist/types/schema/program-accounts/query.d.ts.map +1 -0
  29. package/dist/types/schema/program-accounts/types.d.ts.map +1 -0
  30. package/dist/types/schema/scalars.d.ts.map +1 -0
  31. package/dist/types/schema/transaction/index.d.ts.map +1 -0
  32. package/dist/types/schema/transaction/query.d.ts +1 -1
  33. package/dist/types/schema/transaction/query.d.ts.map +1 -0
  34. package/dist/types/schema/transaction/types.d.ts.map +1 -0
  35. package/package.json +12 -11
@@ -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
  };
@@ -123,8 +138,8 @@ function createSolanaGraphQLContext(rpc) {
123
138
  const cache = createGraphQLCache();
124
139
  return {
125
140
  cache,
126
- resolveAccount(args) {
127
- return resolveAccount(args, this.cache, this.rpc);
141
+ resolveAccount(args, info) {
142
+ return resolveAccount(args, this.cache, this.rpc, info);
128
143
  },
129
144
  resolveBlock(args) {
130
145
  return resolveBlock(args, this.cache, this.rpc);
@@ -341,6 +356,7 @@ var memoisedAccountInterfaceFields;
341
356
  var accountInterfaceFields = () => {
342
357
  if (!memoisedAccountInterfaceFields) {
343
358
  memoisedAccountInterfaceFields = {
359
+ address: string(),
344
360
  encoding: string(),
345
361
  executable: boolean(),
346
362
  lamports: bigint(),
@@ -400,6 +416,7 @@ var accountType = (name, description, data) => new GraphQLObjectType({
400
416
  fields: {
401
417
  ...accountInterfaceFields(),
402
418
  data,
419
+ // Nested Account interface
403
420
  owner: {
404
421
  args: {
405
422
  commitment: type(commitmentInputType()),
@@ -407,7 +424,7 @@ var accountType = (name, description, data) => new GraphQLObjectType({
407
424
  encoding: type(accountEncodingInputType()),
408
425
  minContextSlot: bigint()
409
426
  },
410
- resolve: (parent, args, context) => context.resolveAccount({ ...args, address: parent.owner }),
427
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.owner }, info),
411
428
  type: accountInterface()
412
429
  }
413
430
  },
@@ -451,7 +468,18 @@ var accountNonceAccount = () => {
451
468
  "NonceAccount",
452
469
  "A nonce account",
453
470
  accountDataJsonParsed("Nonce", {
454
- authority: string(),
471
+ // Nested Account interface
472
+ authority: {
473
+ args: {
474
+ commitment: type(commitmentInputType()),
475
+ dataSlice: type(dataSliceInputType()),
476
+ encoding: type(accountEncodingInputType()),
477
+ minContextSlot: bigint()
478
+ },
479
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
480
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authority }, info),
481
+ type: accountInterface()
482
+ },
455
483
  blockhash: string(),
456
484
  feeCalculator: object("NonceFeeCalculator", {
457
485
  lamportsPerSignature: string()
@@ -468,7 +496,18 @@ var accountLookupTable = () => {
468
496
  "An address lookup table account",
469
497
  accountDataJsonParsed("LookupTable", {
470
498
  addresses: list(string()),
471
- authority: string(),
499
+ // Nested Account interface
500
+ authority: {
501
+ args: {
502
+ commitment: type(commitmentInputType()),
503
+ dataSlice: type(dataSliceInputType()),
504
+ encoding: type(accountEncodingInputType()),
505
+ minContextSlot: bigint()
506
+ },
507
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
508
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authority }, info),
509
+ type: accountInterface()
510
+ },
472
511
  deactivationSlot: string(),
473
512
  lastExtendedSlot: string(),
474
513
  lastExtendedSlotStartIndex: number()
@@ -486,7 +525,18 @@ var accountMint = () => {
486
525
  decimals: number(),
487
526
  freezeAuthority: string(),
488
527
  isInitialized: boolean(),
489
- mintAuthority: string(),
528
+ // Nested Account interface
529
+ mintAuthority: {
530
+ args: {
531
+ commitment: type(commitmentInputType()),
532
+ dataSlice: type(dataSliceInputType()),
533
+ encoding: type(accountEncodingInputType()),
534
+ minContextSlot: bigint()
535
+ },
536
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
537
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.mintAuthority }, info),
538
+ type: accountInterface()
539
+ },
490
540
  supply: string()
491
541
  })
492
542
  );
@@ -501,7 +551,18 @@ var accountTokenAccount = () => {
501
551
  accountDataJsonParsed("TokenAccount", {
502
552
  isNative: boolean(),
503
553
  mint: string(),
504
- owner: string(),
554
+ // Nested Account interface
555
+ owner: {
556
+ args: {
557
+ commitment: type(commitmentInputType()),
558
+ dataSlice: type(dataSliceInputType()),
559
+ encoding: type(accountEncodingInputType()),
560
+ minContextSlot: bigint()
561
+ },
562
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
563
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.owner }, info),
564
+ type: accountInterface()
565
+ },
505
566
  state: string(),
506
567
  tokenAmount: type(tokenAmountType())
507
568
  })
@@ -517,11 +578,44 @@ var accountStakeAccount = () => {
517
578
  accountDataJsonParsed("Stake", {
518
579
  meta: object("StakeMeta", {
519
580
  authorized: object("StakeMetaAuthorized", {
520
- staker: string(),
521
- withdrawer: string()
581
+ // Nested Account interface
582
+ staker: {
583
+ args: {
584
+ commitment: type(commitmentInputType()),
585
+ dataSlice: type(dataSliceInputType()),
586
+ encoding: type(accountEncodingInputType()),
587
+ minContextSlot: bigint()
588
+ },
589
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
590
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.staker }, info),
591
+ type: accountInterface()
592
+ },
593
+ // Nested Account interface
594
+ withdrawer: {
595
+ args: {
596
+ commitment: type(commitmentInputType()),
597
+ dataSlice: type(dataSliceInputType()),
598
+ encoding: type(accountEncodingInputType()),
599
+ minContextSlot: bigint()
600
+ },
601
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
602
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.withdrawer }, info),
603
+ type: accountInterface()
604
+ }
522
605
  }),
523
606
  lockup: object("StakeMetaLockup", {
524
- custodian: string(),
607
+ // Nested Account interface
608
+ custodian: {
609
+ args: {
610
+ commitment: type(commitmentInputType()),
611
+ dataSlice: type(dataSliceInputType()),
612
+ encoding: type(accountEncodingInputType()),
613
+ minContextSlot: bigint()
614
+ },
615
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
616
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.custodian }, info),
617
+ type: accountInterface()
618
+ },
525
619
  epoch: bigint(),
526
620
  unixTimestamp: bigint()
527
621
  }),
@@ -533,7 +627,18 @@ var accountStakeAccount = () => {
533
627
  activationEpoch: bigint(),
534
628
  deactivationEpoch: bigint(),
535
629
  stake: string(),
536
- voter: string(),
630
+ // Nested Account interface
631
+ voter: {
632
+ args: {
633
+ commitment: type(commitmentInputType()),
634
+ dataSlice: type(dataSliceInputType()),
635
+ encoding: type(accountEncodingInputType()),
636
+ minContextSlot: bigint()
637
+ },
638
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
639
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.voter }, info),
640
+ type: accountInterface()
641
+ },
537
642
  warmupCooldownRate: number()
538
643
  })
539
644
  })
@@ -550,11 +655,33 @@ var accountVoteAccount = () => {
550
655
  accountDataJsonParsed("Vote", {
551
656
  authorizedVoters: list(
552
657
  object("VoteAuthorizedVoter", {
553
- authorizedVoter: string(),
658
+ // Nested Account interface
659
+ authorizedVoter: {
660
+ args: {
661
+ commitment: type(commitmentInputType()),
662
+ dataSlice: type(dataSliceInputType()),
663
+ encoding: type(accountEncodingInputType()),
664
+ minContextSlot: bigint()
665
+ },
666
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
667
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authorizedVoter }, info),
668
+ type: accountInterface()
669
+ },
554
670
  epoch: bigint()
555
671
  })
556
672
  ),
557
- authorizedWithdrawer: string(),
673
+ // Nested Account interface
674
+ authorizedWithdrawer: {
675
+ args: {
676
+ commitment: type(commitmentInputType()),
677
+ dataSlice: type(dataSliceInputType()),
678
+ encoding: type(accountEncodingInputType()),
679
+ minContextSlot: bigint()
680
+ },
681
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
682
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authorizedWithdrawer }, info),
683
+ type: accountInterface()
684
+ },
558
685
  commission: number(),
559
686
  epochCredits: list(
560
687
  object("VoteEpochCredits", {
@@ -567,7 +694,18 @@ var accountVoteAccount = () => {
567
694
  slot: bigint(),
568
695
  timestamp: bigint()
569
696
  }),
570
- nodePubkey: string(),
697
+ // Nested Account interface
698
+ node: {
699
+ args: {
700
+ commitment: type(commitmentInputType()),
701
+ dataSlice: type(dataSliceInputType()),
702
+ encoding: type(accountEncodingInputType()),
703
+ minContextSlot: bigint()
704
+ },
705
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
706
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.nodePubkey }, info),
707
+ type: accountInterface()
708
+ },
571
709
  priorVoters: list(string()),
572
710
  rootSlot: bigint(),
573
711
  votes: list(
@@ -607,7 +745,8 @@ var accountQuery = () => ({
607
745
  encoding: type(accountEncodingInputType()),
608
746
  minContextSlot: bigint()
609
747
  },
610
- resolve: (_parent, args, context) => context.resolveAccount(args),
748
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
749
+ resolve: (_parent, args, context, info) => context.resolveAccount(args, info),
611
750
  type: accountInterface()
612
751
  }
613
752
  });