import { ApiV3 } from '../Types'; import { GqlError, GqlHttpResponse, GqlExtensions } from '../Types/GraphQL'; interface QueryResult { errors?: GqlError[]; data?: T; extensions?: GqlExtensions; } /** * Queries the GraphQL API. * * @param apiV3 the v3 API instance to use * @param query the GQL query * @param variables named variables to substitute into the query, if any * @returns {GqlHttpResponse} if successful * @throws {HttpError} if it receives a non-2XX result */ export async function graphql( apiV3: ApiV3.API, query: string, variables?: { [key: string]: any } ): Promise> { const response = await apiV3.post>('/graphql', { query, variables }); const { data, extensions, errors } = response.data; return { ...response, data, extensions, errors }; }