@krakentech/blueprint-utils
This is our package of reusable utilities that we've developed for working with the Kraken API. You can install this package via npm with an organisation token - please get in touch if you need one.
API reference
getFirstGraphQLErrorCode
A helper function that returns the first error code from an array of Apollo GraphQL errors.
Import
import { getFirstGraphQLErrorCode } from '@krakentech/blueprint-utils';
Usage
import type { ApolloError } from '@apollo/client';
const errors: ApolloError[] = [
{
extensions: {
errorCode: 'KT-1111',
},
},
{
extensions: {
errorCode: 'KT-2222',
},
},
];
const firstErrorCode = getFirstGraphQLErrorCode<ApolloError>(errors);
Args
Name | Description | Type | Default | Required |
---|---|---|---|---|
errors | Array of errors from which to get the first | T[] | true |
useApolloPagination
A hook to assist with paginating data from Apollo, which while not used in Blueprint anymore, was used in previous versions.
Import
import { useApolloPagination } from '@krakentech/blueprint-utils';
Usage
import { useApolloPagination, mergeResults } from '@krakentech/blueprint-utils';
const { data, loading, error, fetchMore } = useQuery(QUERY, {
variables: { accountNumber },
});
const { onLoadMore, hasNextPage } = useApolloPagination({
fetchMore,
pageInfo: data.pageInfo,
mergeData: mergeResults,
});