import { GraphQLError } from "../erp-api-services/errors.js"; import type { GraphQLServerError } from "../erp-api-services/graphql/types.js"; /** * JSON body for POST to MM API `/proxy/graphql` (MachineMetrics GraphQL proxy). * Used only by `MMApiClient` (not exported from the public SDK entrypoint). */ export function buildMmGraphqlProxyRequestBody( operationName: string, query: string, variables?: Record ): Record { const body: Record = { operationName, query }; if (variables !== undefined && Object.keys(variables).length > 0) { body.variables = variables; } return body; } /** * GraphQL-over-HTTP often returns **HTTP 200** with a top-level `errors` array and partial or null `data`. * Axios treats that as success, so callers must inspect the envelope. * * @throws {GraphQLError} when `errors` is a non-empty array */ export function assertMmGraphqlProxyResponseHasNoErrors( response: Record ): void { const errors = response.errors; if (Array.isArray(errors) && errors.length > 0) { throw new GraphQLError("GraphQL Error", errors as GraphQLServerError[]); } }