A TypeScript library for interacting with the M3ter GraphQL API.
npm install graphql-m3ter-client
import { MeterClient } from "graphql-m3ter-client";
// Initialize the client with your GraphQL endpoint
const client = new MeterClient({
endpoint: "https://your-graphql-endpoint.com/graphql",
headers: {
Authorization: "Bearer YOUR_TOKEN", // Optional
},
});
// Get all meters
async function getAllMeters() {
const meters = await client.meters.getMeters();
console.log(meters);
}
// Get a specific meter
async function getMeter() {
const meter = await client.meters.getMeter({ meterNumber: "METER123" });
console.log(meter);
}
// Get meter data points with pagination
async function getMeterDataPoints() {
const dataPointEdges = await client.dataPoints.getMeterDataPoints({
meterNumber: "METER123",
first: 10,
sortBy: "HEIGHT_DESC",
});
console.log(dataPointEdges);
}
The library also supports executing custom GraphQL queries:
async function executeCustomQuery() {
const customQuery = `
query GetCustomData($id: String!) {
customEntity(id: $id) {
field1
field2
}
}
`;
const result = await client.executeCustomQuery(customQuery, { id: "123" });
console.log(result);
}
You can change the GraphQL endpoint at runtime:
// Switch to a different subgraph
client.setEndpoint("https://different-graphql-endpoint.com/graphql");
// Set or update authentication headers
client.setHeaders({
Authorization: "Bearer NEW_TOKEN",
});
// Add additional headers
client.addHeaders({
"X-Custom-Header": "CustomValue",
});
The main client class for interacting with the API.
new MeterClient({
endpoint: string;
headers?: Record<string, string>;
})
setEndpoint(endpoint: string)
: Update the GraphQL endpoint URLsetHeaders(headers: Record<string, string>)
: Set custom headersaddHeaders(headers: Record<string, string>)
: Add additional headersexecuteCustomQuery<T>(query: string, variables?: Record<string, any>)
: Execute a custom GraphQL query
meters
: Access meters APIdataPoints
: Access data points API
Methods for working with meter data.
getMeters()
: Get all metersgetMeter({ meterNumber?: string, contractId?: string })
: Get a specific meter
Methods for working with meter data points.
getMeterDataPoints(params: MeterDataPointsQueryParams)
: Get meter data points with pagination and sorting
MIT