Skip to Content
Octopus Energy Packages
Migration

Migrating to v1

Migrate from the old hook-based API to the composable measurements architecture

The old API (v0) was a direct port from @krakentech/blueprint-utils, built around two opaque hooks (useMeasurements and useMeasurementFilters) that were tightly coupled to @krakentech/blueprint-api.

The new API (v1) removes that dependency entirely. You bring your own GraphQL client, and the package handles state, fetching, grouping, transforms, and Coral compatibility through composable, tree-shakeable entry points.

What's changing

Peer dependencyBeforeAfter
@krakentech/blueprint-apiRequiredRemoved
@tanstack/react-queryRequiredOptional (only @octopus-energy/measurements/react-query)
reactRequiredOptional (only useTimeframe, usePreferences hooks)
nuqsN/AOptional (only @octopus-energy/measurements/storage/nuqs)

Set up your GraphQL client

The old API used useApi() from @krakentech/blueprint-api internally. The new API accepts any object satisfying the GraphQLClient interface:

interface GraphQLClient {
  request<TResult, TVariables>(
    document: TypedDocumentNode<TResult, TVariables>,
    variables: TVariables,
  ): Promise<TResult>;
}
Client-side
import { useGraphQLClient } from "#/lib/auth/client";

const client = useGraphQLClient();
Server-side
import { getUserScopedGraphQLClient } from "#/lib/auth/server";

const client = getUserScopedGraphQLClient();

Pass this client as the first argument to any function that fetches data (query options factories, fetch functions, and resolvers).

Install the package

npm i @octopus-energy/measurements@latest

If you were importing from @krakentech/blueprint-utils, you can remove it from your dependencies once the migration is complete.

Choose your migration path

Pick the feature you're migrating.

If you're migrating both features, start with EnergyOverview because the state management and data fetching setup is shared. Once EnergyOverview is working, EnergySummary only needs a different transform and compat mapping.

On this page