Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(experimental): graphql: relay: Add support for id field in transactions #2565

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/rpc-graphql/src/__tests__/transaction-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,23 @@ describe('transaction', () => {
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
ID
blockTime
slot
}
}
`;
const result = await rpcGraphQL.query(source, { signature });
const result = await rpcGraphQL.query(source, { ID: signature, signature });
expect(result).toMatchObject({
data: {
transaction: {
ID: expect.any(signature),
blockTime: expect.any(BigInt),
slot: expect.any(BigInt),
},
},
});
expect((result?.data?.transaction as { ID: string })?.ID).toBe(signature);
});
it("can query a transaction's computeUnitsConsumed from it's meta", async () => {
expect.assertions(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenLastCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'jsonParsed',
},
Expand All @@ -127,6 +128,7 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenLastCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'base64', // GraphQL client prefers `base64`
},
Expand Down Expand Up @@ -156,13 +158,15 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'base64', // GraphQL client prefers `base64`
},
);
expect(rpc.getTransaction).toHaveBeenCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'finalized',
encoding: 'base64', // GraphQL client prefers `base64`
},
Expand All @@ -187,6 +191,7 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenLastCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'base64',
},
Expand All @@ -209,6 +214,7 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenLastCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'base58',
},
Expand All @@ -231,6 +237,7 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenLastCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'base64',
},
Expand Down Expand Up @@ -262,6 +269,7 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenLastCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'jsonParsed',
},
Expand All @@ -286,6 +294,7 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenLastCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'base58',
},
Expand All @@ -310,6 +319,7 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenLastCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'base64',
},
Expand Down Expand Up @@ -341,6 +351,7 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenLastCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'jsonParsed',
},
Expand Down Expand Up @@ -382,6 +393,7 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenLastCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'jsonParsed',
},
Expand Down Expand Up @@ -414,13 +426,15 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'base64',
},
);
expect(rpc.getTransaction).toHaveBeenCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'jsonParsed',
},
Expand Down Expand Up @@ -458,20 +472,23 @@ describe('account loader', () => {
expect(rpc.getTransaction).toHaveBeenCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'base58',
},
);
expect(rpc.getTransaction).toHaveBeenCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'base64',
},
);
expect(rpc.getTransaction).toHaveBeenCalledWith(
'67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
{
ID: '67rSZV97NzE4B4ZeFqULqWZcNEV2KwNfDLMzecJmBheZ4sWhudqGAzypoBCKfeLkKtDQBGnkwgdrrFM8ZMaS3pkk',
commitment: 'confirmed',
encoding: 'jsonParsed',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function buildTransactionArgSetWithVisitor<TArgs extends BlockLoaderArgs
*/
export function buildTransactionLoaderArgSetFromResolveInfo(
args: {
ID: Signature;
commitment?: Omit<Commitment, 'processed'>;
minContextSlot?: Slot;
signature: Signature;
Expand Down
8 changes: 5 additions & 3 deletions packages/rpc-graphql/src/resolvers/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type InstructionResult = {
};

export type TransactionResult = Partial<TransactionLoaderValue> & {
ID?: Signature;
encodedData?: EncodedTransactionData;
signature?: Signature;
};
Expand Down Expand Up @@ -96,13 +97,14 @@ export function resolveTransaction(fieldName?: string) {

if (signature) {
if (onlyFieldsRequested(['signature'], info)) {
return { signature };
return { ID: signature, signature };
}

const argsSet = buildTransactionLoaderArgSetFromResolveInfo({ ...args, signature }, info);
const argsSet = buildTransactionLoaderArgSetFromResolveInfo({ ...args, ID: signature, signature }, info);
const loadedTransactions = await context.loaders.transaction.loadMany(argsSet);

const nonNullSignature = signature!;
let result: TransactionResult = {
ID: nonNullSignature,
encodedData: {},
signature,
};
Expand Down
1 change: 1 addition & 0 deletions packages/rpc-graphql/src/schema/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const transactionTypeDefs = /* GraphQL */ `
A Solana transaction
"""
type Transaction {
id: ID!
blockTime: BigInt
data(encoding: TransactionEncoding!): String
message: TransactionMessage
Expand Down
2 changes: 1 addition & 1 deletion packages/test-config/test-validator-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = async function globalSetup() {
{
command: 'while true; do sleep 86400000; done',
host: '127.0.0.1',
launchTimeout: 50000,
launchTimeout: 999999,
path: 'health',
port: 8899,
protocol: 'http',
Expand Down