Skip to content

Commit

Permalink
feat: implement get blob as custom query
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbate committed Aug 30, 2024
1 parent 36facf5 commit 306f4b7
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { equalBytes } from '@noble/curves/abstract/utils';
import type { DocumentNode } from 'graphql';
import { GraphQLClient } from 'graphql-request';
import type { GraphQLResponse } from 'graphql-request/src/types';
import gql from 'graphql-tag';
import { clone } from 'ramda';

import { getSdk as getOperationsSdk } from './__generated__/operations';
Expand All @@ -27,6 +28,7 @@ import type {
GqlPageInfo,
GqlRelayedTransactionFailed,
GqlMessage,
Requester,
} from './__generated__/operations';
import type { Coin } from './coin';
import type { CoinQuantity, CoinQuantityLike } from './coin-quantity';
Expand Down Expand Up @@ -376,6 +378,7 @@ type SdkOperations = Omit<Operations, 'submitAndAwait' | 'statusChange'> & {
statusChange: (
...args: Parameters<Operations['statusChange']>
) => Promise<ReturnType<Operations['statusChange']>>;
getBlobCustom: (variables: { blobId: string }) => Promise<{ blob?: { id: string } | null }>;
};

/**
Expand Down Expand Up @@ -603,8 +606,22 @@ Supported fuel-core version: ${supportedVersion}.`
return gqlClient.request(query, vars);
};

const customOperations = (requester: Requester) => ({
getBlobCustom(variables: { blobId: string }) {
const document = gql`
query getBlob($blobId: BlobId!) {
blob(id: $blobId) {
id
}
}
`;

return requester(document, variables);
},
});

// @ts-expect-error This is due to this function being generic. Its type is specified when calling a specific operation via provider.operations.xyz.
return getOperationsSdk(executeQuery);
return { ...getOperationsSdk(executeQuery), ...customOperations(executeQuery) };
}

/**
Expand Down Expand Up @@ -1337,8 +1354,8 @@ Supported fuel-core version: ${supportedVersion}.`
* @returns A promise that resolves to the blob ID or null.
*/
async getBlob(blobId: string): Promise<string | null> {
const { blob } = await this.operations.getBlob({ blobId });
return blob?.id;
const { blob } = await this.operations.getBlobCustom({ blobId });
return blob?.id ?? null;
}

/**
Expand Down

0 comments on commit 306f4b7

Please sign in to comment.