2024-01-17 08:52:15 +00:00
|
|
|
import { ApolloClient, InMemoryCache, NormalizedCacheObject } from '@apollo/client';
|
|
|
|
|
2024-01-19 09:52:25 +00:00
|
|
|
import { getUser, getOrganizations, getDeployments } from './queries';
|
2024-01-17 08:52:15 +00:00
|
|
|
|
|
|
|
export interface GraphQLConfig {
|
|
|
|
gqlEndpoint: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GQLClient {
|
|
|
|
private client: ApolloClient<NormalizedCacheObject>;
|
|
|
|
|
|
|
|
constructor (config: GraphQLConfig) {
|
|
|
|
this.client = new ApolloClient({
|
|
|
|
uri: config.gqlEndpoint,
|
|
|
|
cache: new InMemoryCache()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getUser () : Promise<any> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getUser
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-18 04:34:02 +00:00
|
|
|
|
|
|
|
async getOrganizations () : Promise<any> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getOrganizations
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-18 12:20:50 +00:00
|
|
|
|
|
|
|
async getDeployments (projectId: string) : Promise<any> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getDeployments,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-17 08:52:15 +00:00
|
|
|
}
|