Skip to content

Commit

Permalink
feat: return data from response
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Changes return value of `sendQuery` method from `Promise<GraphQlResponse<T>> to `Promise<[key: string]: T[]>
  • Loading branch information
annarieger committed Jun 28, 2022
1 parent 16a4822 commit 8c02fe2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/service/GraphQLService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class GraphQLService {
this.keycloak = opts.keycloak;
}

async sendQuery<T>(query: GraphQLQueryObject, fetchOpts?: RequestInit): Promise<GraphQLResponse<T>> {
async sendQuery<T>(query: GraphQLQueryObject, fetchOpts?: RequestInit): Promise<any> {
try {
const response = await fetch(this.basePath, {
method: 'POST',
Expand All @@ -46,17 +46,17 @@ export class GraphQLService {
...fetchOpts
});

if (!response.ok) {
throw new Error(`HTTP error status: ${response.status}`);
if (!response?.ok) {
throw new Error(`HTTP error status: ${response?.status}`);
}

const responseJson = await response.json() as GraphQLResponse<T>;
const {data, errors } = await response.json() as GraphQLResponse<T>;

if (responseJson.errors?.length > 0) {
throw new Error(`Error response: ${responseJson.errors}`);
if (errors?.length > 0) {
throw new Error(`Error response: ${errors}`);
}

return responseJson;
return data;
} catch (error) {
throw new Error(`Error while requesting GraphQL: ${error}`);
}
Expand Down

0 comments on commit 8c02fe2

Please sign in to comment.