@solana/rpc-graphql 2.0.0-experimental.ee4214c → 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
@@ -38,7 +38,19 @@ function createGraphQLCache() {
38
38
  }
39
39
 
40
40
  // src/context.ts
41
- async function resolveAccount({ address, encoding = "jsonParsed", ...config }, cache, rpc) {
41
+ async function resolveAccount({ address, encoding = "jsonParsed", ...config }, cache, rpc, info) {
42
+ if (info && info.fieldNodes[0].selectionSet) {
43
+ const selectionSet = info.fieldNodes[0].selectionSet;
44
+ const requestedFields = selectionSet.selections.map((field) => {
45
+ if (field.kind === "Field") {
46
+ return field.name.value;
47
+ }
48
+ return null;
49
+ });
50
+ if (requestedFields && requestedFields.length === 1 && requestedFields[0] === "address") {
51
+ return { address };
52
+ }
53
+ }
42
54
  const requestConfig = { encoding, ...config };
43
55
  const cached = cache.get(address, requestConfig);
44
56
  if (cached !== null) {
@@ -48,11 +60,14 @@ async function resolveAccount({ address, encoding = "jsonParsed", ...config }, c
48
60
  throw e;
49
61
  });
50
62
  if (account === null) {
51
- return null;
63
+ return {
64
+ address
65
+ };
52
66
  }
53
67
  const [data, responseEncoding] = Array.isArray(account.data) ? encoding === "jsonParsed" ? [account.data[0], "base64"] : [account.data[0], encoding] : [account.data, "jsonParsed"];
54
68
  const queryResponse = {
55
69
  ...account,
70
+ address,
56
71
  data,
57
72
  encoding: responseEncoding
58
73
  };
@@ -127,8 +142,8 @@ function createSolanaGraphQLContext(rpc) {
127
142
  const cache = createGraphQLCache();
128
143
  return {
129
144
  cache,
130
- resolveAccount(args) {
131
- return resolveAccount(args, this.cache, this.rpc);
145
+ resolveAccount(args, info) {
146
+ return resolveAccount(args, this.cache, this.rpc, info);
132
147
  },
133
148
  resolveBlock(args) {
134
149
  return resolveBlock(args, this.cache, this.rpc);
@@ -345,6 +360,7 @@ var memoisedAccountInterfaceFields;
345
360
  var accountInterfaceFields = () => {
346
361
  if (!memoisedAccountInterfaceFields) {
347
362
  memoisedAccountInterfaceFields = {
363
+ address: string(),
348
364
  encoding: string(),
349
365
  executable: boolean(),
350
366
  lamports: bigint(),
@@ -404,6 +420,7 @@ var accountType = (name, description, data) => new GraphQLObjectType({
404
420
  fields: {
405
421
  ...accountInterfaceFields(),
406
422
  data,
423
+ // Nested Account interface
407
424
  owner: {
408
425
  args: {
409
426
  commitment: type(commitmentInputType()),
@@ -411,7 +428,7 @@ var accountType = (name, description, data) => new GraphQLObjectType({
411
428
  encoding: type(accountEncodingInputType()),
412
429
  minContextSlot: bigint()
413
430
  },
414
- resolve: (parent, args, context) => context.resolveAccount({ ...args, address: parent.owner }),
431
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.owner }, info),
415
432
  type: accountInterface()
416
433
  }
417
434
  },
@@ -455,7 +472,18 @@ var accountNonceAccount = () => {
455
472
  "NonceAccount",
456
473
  "A nonce account",
457
474
  accountDataJsonParsed("Nonce", {
458
- authority: string(),
475
+ // Nested Account interface
476
+ authority: {
477
+ args: {
478
+ commitment: type(commitmentInputType()),
479
+ dataSlice: type(dataSliceInputType()),
480
+ encoding: type(accountEncodingInputType()),
481
+ minContextSlot: bigint()
482
+ },
483
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
484
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authority }, info),
485
+ type: accountInterface()
486
+ },
459
487
  blockhash: string(),
460
488
  feeCalculator: object("NonceFeeCalculator", {
461
489
  lamportsPerSignature: string()
@@ -472,7 +500,18 @@ var accountLookupTable = () => {
472
500
  "An address lookup table account",
473
501
  accountDataJsonParsed("LookupTable", {
474
502
  addresses: list(string()),
475
- authority: string(),
503
+ // Nested Account interface
504
+ authority: {
505
+ args: {
506
+ commitment: type(commitmentInputType()),
507
+ dataSlice: type(dataSliceInputType()),
508
+ encoding: type(accountEncodingInputType()),
509
+ minContextSlot: bigint()
510
+ },
511
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
512
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authority }, info),
513
+ type: accountInterface()
514
+ },
476
515
  deactivationSlot: string(),
477
516
  lastExtendedSlot: string(),
478
517
  lastExtendedSlotStartIndex: number()
@@ -490,7 +529,18 @@ var accountMint = () => {
490
529
  decimals: number(),
491
530
  freezeAuthority: string(),
492
531
  isInitialized: boolean(),
493
- mintAuthority: string(),
532
+ // Nested Account interface
533
+ mintAuthority: {
534
+ args: {
535
+ commitment: type(commitmentInputType()),
536
+ dataSlice: type(dataSliceInputType()),
537
+ encoding: type(accountEncodingInputType()),
538
+ minContextSlot: bigint()
539
+ },
540
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
541
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.mintAuthority }, info),
542
+ type: accountInterface()
543
+ },
494
544
  supply: string()
495
545
  })
496
546
  );
@@ -505,7 +555,18 @@ var accountTokenAccount = () => {
505
555
  accountDataJsonParsed("TokenAccount", {
506
556
  isNative: boolean(),
507
557
  mint: string(),
508
- owner: string(),
558
+ // Nested Account interface
559
+ owner: {
560
+ args: {
561
+ commitment: type(commitmentInputType()),
562
+ dataSlice: type(dataSliceInputType()),
563
+ encoding: type(accountEncodingInputType()),
564
+ minContextSlot: bigint()
565
+ },
566
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
567
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.owner }, info),
568
+ type: accountInterface()
569
+ },
509
570
  state: string(),
510
571
  tokenAmount: type(tokenAmountType())
511
572
  })
@@ -521,11 +582,44 @@ var accountStakeAccount = () => {
521
582
  accountDataJsonParsed("Stake", {
522
583
  meta: object("StakeMeta", {
523
584
  authorized: object("StakeMetaAuthorized", {
524
- staker: string(),
525
- withdrawer: string()
585
+ // Nested Account interface
586
+ staker: {
587
+ args: {
588
+ commitment: type(commitmentInputType()),
589
+ dataSlice: type(dataSliceInputType()),
590
+ encoding: type(accountEncodingInputType()),
591
+ minContextSlot: bigint()
592
+ },
593
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
594
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.staker }, info),
595
+ type: accountInterface()
596
+ },
597
+ // Nested Account interface
598
+ withdrawer: {
599
+ args: {
600
+ commitment: type(commitmentInputType()),
601
+ dataSlice: type(dataSliceInputType()),
602
+ encoding: type(accountEncodingInputType()),
603
+ minContextSlot: bigint()
604
+ },
605
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
606
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.withdrawer }, info),
607
+ type: accountInterface()
608
+ }
526
609
  }),
527
610
  lockup: object("StakeMetaLockup", {
528
- custodian: string(),
611
+ // Nested Account interface
612
+ custodian: {
613
+ args: {
614
+ commitment: type(commitmentInputType()),
615
+ dataSlice: type(dataSliceInputType()),
616
+ encoding: type(accountEncodingInputType()),
617
+ minContextSlot: bigint()
618
+ },
619
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
620
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.custodian }, info),
621
+ type: accountInterface()
622
+ },
529
623
  epoch: bigint(),
530
624
  unixTimestamp: bigint()
531
625
  }),
@@ -537,7 +631,18 @@ var accountStakeAccount = () => {
537
631
  activationEpoch: bigint(),
538
632
  deactivationEpoch: bigint(),
539
633
  stake: string(),
540
- voter: string(),
634
+ // Nested Account interface
635
+ voter: {
636
+ args: {
637
+ commitment: type(commitmentInputType()),
638
+ dataSlice: type(dataSliceInputType()),
639
+ encoding: type(accountEncodingInputType()),
640
+ minContextSlot: bigint()
641
+ },
642
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
643
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.voter }, info),
644
+ type: accountInterface()
645
+ },
541
646
  warmupCooldownRate: number()
542
647
  })
543
648
  })
@@ -554,11 +659,33 @@ var accountVoteAccount = () => {
554
659
  accountDataJsonParsed("Vote", {
555
660
  authorizedVoters: list(
556
661
  object("VoteAuthorizedVoter", {
557
- authorizedVoter: string(),
662
+ // Nested Account interface
663
+ authorizedVoter: {
664
+ args: {
665
+ commitment: type(commitmentInputType()),
666
+ dataSlice: type(dataSliceInputType()),
667
+ encoding: type(accountEncodingInputType()),
668
+ minContextSlot: bigint()
669
+ },
670
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
671
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authorizedVoter }, info),
672
+ type: accountInterface()
673
+ },
558
674
  epoch: bigint()
559
675
  })
560
676
  ),
561
- authorizedWithdrawer: string(),
677
+ // Nested Account interface
678
+ authorizedWithdrawer: {
679
+ args: {
680
+ commitment: type(commitmentInputType()),
681
+ dataSlice: type(dataSliceInputType()),
682
+ encoding: type(accountEncodingInputType()),
683
+ minContextSlot: bigint()
684
+ },
685
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
686
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.authorizedWithdrawer }, info),
687
+ type: accountInterface()
688
+ },
562
689
  commission: number(),
563
690
  epochCredits: list(
564
691
  object("VoteEpochCredits", {
@@ -571,7 +698,18 @@ var accountVoteAccount = () => {
571
698
  slot: bigint(),
572
699
  timestamp: bigint()
573
700
  }),
574
- nodePubkey: string(),
701
+ // Nested Account interface
702
+ node: {
703
+ args: {
704
+ commitment: type(commitmentInputType()),
705
+ dataSlice: type(dataSliceInputType()),
706
+ encoding: type(accountEncodingInputType()),
707
+ minContextSlot: bigint()
708
+ },
709
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
710
+ resolve: (parent, args, context, info) => context.resolveAccount({ ...args, address: parent.nodePubkey }, info),
711
+ type: accountInterface()
712
+ },
575
713
  priorVoters: list(string()),
576
714
  rootSlot: bigint(),
577
715
  votes: list(
@@ -611,7 +749,8 @@ var accountQuery = () => ({
611
749
  encoding: type(accountEncodingInputType()),
612
750
  minContextSlot: bigint()
613
751
  },
614
- resolve: (_parent, args, context) => context.resolveAccount(args),
752
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
753
+ resolve: (_parent, args, context, info) => context.resolveAccount(args, info),
615
754
  type: accountInterface()
616
755
  }
617
756
  });