Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
refactor(experimental-graphql): revise accounts schema (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Nov 12, 2023
1 parent 26136d9 commit 2576806
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 60 deletions.
102 changes: 52 additions & 50 deletions packages/rpc-graphql/src/__tests__/account-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ describe('account', () => {
const source = /* GraphQL */ `
query testQuery($address: String!, $encoding: AccountEncoding) {
account(address: $address, encoding: $encoding) {
address
... on AccountBase58 {
data
}
Expand All @@ -238,6 +239,7 @@ describe('account', () => {
expect(result).toMatchObject({
data: {
account: {
address: 'CcYNb7WqpjaMrNr7B1mapaNfWctZRH7LyAjWRLBGt1Fk',
data: '2Uw1bpnsXxu3e',
},
},
Expand All @@ -253,6 +255,7 @@ describe('account', () => {
const source = /* GraphQL */ `
query testQuery($address: String!, $encoding: AccountEncoding) {
account(address: $address, encoding: $encoding) {
address
... on AccountBase64 {
data
}
Expand All @@ -263,6 +266,7 @@ describe('account', () => {
expect(result).toMatchObject({
data: {
account: {
address: 'CcYNb7WqpjaMrNr7B1mapaNfWctZRH7LyAjWRLBGt1Fk',
data: 'dGVzdCBkYXRh',
},
},
Expand All @@ -278,6 +282,7 @@ describe('account', () => {
const source = /* GraphQL */ `
query testQuery($address: String!, $encoding: AccountEncoding) {
account(address: $address, encoding: $encoding) {
address
... on AccountBase64Zstd {
data
}
Expand All @@ -288,13 +293,60 @@ describe('account', () => {
expect(result).toMatchObject({
data: {
account: {
address: 'CcYNb7WqpjaMrNr7B1mapaNfWctZRH7LyAjWRLBGt1Fk',
data: 'KLUv/QBYSQAAdGVzdCBkYXRh',
},
},
});
});
});
describe('specific account type queries', () => {
it('can get a nonce account', async () => {
expect.assertions(1);
// See scripts/fixtures/nonce-account.json
const variableValues = {
address: 'AiZExP8mK4RxDozh4r57knvqSZgkz86HrzPAMx61XMqU',
};
const source = /* GraphQL */ `
query testQuery($address: String!) {
account(address: $address) {
address
lamports
... on NonceAccount {
authority {
address
}
blockhash
feeCalculator {
lamportsPerSignature
}
program
space
type
}
}
}
`;
const result = await rpcGraphQL.query(source, variableValues);
expect(result).toMatchObject({
data: {
account: {
address: 'AiZExP8mK4RxDozh4r57knvqSZgkz86HrzPAMx61XMqU',
authority: {
address: '3xxDCjN8s6MgNHwdRExRLa6gHmmRTWPnUdzkbKfEgNAe',
},
blockhash: expect.any(String),
feeCalculator: {
lamportsPerSignature: expect.any(String),
},
lamports: expect.any(BigInt),
program: 'nonce',
space: 80n,
type: 'initialized',
},
},
});
});
it('can get a mint account', async () => {
expect.assertions(1);
// See scripts/fixtures/spl-token-mint-account.json
Expand Down Expand Up @@ -408,56 +460,6 @@ describe('account', () => {
},
});
});
it('can get a nonce account', async () => {
expect.assertions(1);
// See scripts/fixtures/nonce-account.json
const variableValues = {
address: 'AiZExP8mK4RxDozh4r57knvqSZgkz86HrzPAMx61XMqU',
};
const source = /* GraphQL */ `
query testQuery($address: String!) {
account(address: $address) {
... on NonceAccount {
data {
authority {
address
}
blockhash
feeCalculator {
lamportsPerSignature
}
}
meta {
program
space
type
}
}
}
}
`;
const result = await rpcGraphQL.query(source, variableValues);
expect(result).toMatchObject({
data: {
account: {
data: {
authority: {
address: '3xxDCjN8s6MgNHwdRExRLa6gHmmRTWPnUdzkbKfEgNAe',
},
blockhash: expect.any(String),
feeCalculator: {
lamportsPerSignature: expect.any(String),
},
},
meta: {
program: 'nonce',
space: 80n,
type: 'initialized',
},
},
},
});
});
it('can get a stake account', async () => {
expect.assertions(1);
// See scripts/fixtures/stake-account.json
Expand Down
21 changes: 11 additions & 10 deletions packages/rpc-graphql/src/schema/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,21 @@ export const accountTypeDefs = /* GraphQL */ `
type NonceAccountFeeCalculator {
lamportsPerSignature: String
}
type NonceAccountData {
authority: Account
blockhash: String
feeCalculator: NonceAccountFeeCalculator
}
type NonceAccount implements Account & AccountJsonParsed {
address: String
data: NonceAccountData
encoding: String
executable: Boolean
lamports: BigInt
meta: JsonParsedAccountMeta
owner: Account
rentEpoch: BigInt
# Parsed data:
authority: Account
blockhash: String
feeCalculator: NonceAccountFeeCalculator
# Parsed meta
program: String
space: BigInt
type: String
}
# A lookup table account
Expand Down Expand Up @@ -269,9 +270,9 @@ export const accountResolvers = {
AccountBase64Zstd: {
owner: resolveAccount('owner'),
},
NonceAccountData: {
authority: resolveAccount('authority'),
},
// NonceAccountData: {
// authority: resolveAccount('authority'),
// },
NonceAccount: {
owner: resolveAccount('owner'),
},
Expand Down

0 comments on commit 2576806

Please sign in to comment.