forked from cerc-io/snowballtools-base
cbc394f9f8
* Add remove member gql client method * Handle remove member UI operation * Refactor fetching of project members * Rename type MemberPermission to ProjectMember * Add types to gql client response * Remove circular dependency in gql client types --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
import { ApolloClient, DefaultOptions, InMemoryCache, NormalizedCacheObject } from '@apollo/client';
|
|
|
|
import { getUser, getOrganizations, getDeployments, getProjectMembers } from './queries';
|
|
import { GetDeploymentsResponse, GetOrganizationsResponse, GetProjectMembersResponse, GetUserResponse, RemoveMemberResponse } from './types';
|
|
import { removeMember } from './mutations';
|
|
|
|
export interface GraphQLConfig {
|
|
gqlEndpoint: string;
|
|
}
|
|
|
|
// TODO: check options
|
|
const defaultOptions: DefaultOptions = {
|
|
watchQuery: {
|
|
fetchPolicy: 'no-cache',
|
|
errorPolicy: 'ignore'
|
|
},
|
|
query: {
|
|
fetchPolicy: 'no-cache',
|
|
errorPolicy: 'all'
|
|
}
|
|
};
|
|
|
|
export class GQLClient {
|
|
private client: ApolloClient<NormalizedCacheObject>;
|
|
|
|
constructor (config: GraphQLConfig) {
|
|
this.client = new ApolloClient({
|
|
uri: config.gqlEndpoint,
|
|
cache: new InMemoryCache(),
|
|
defaultOptions
|
|
});
|
|
}
|
|
|
|
async getUser () : Promise<GetUserResponse> {
|
|
const { data } = await this.client.query({
|
|
query: getUser
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
async getOrganizations () : Promise<GetOrganizationsResponse> {
|
|
const { data } = await this.client.query({
|
|
query: getOrganizations
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
async getDeployments (projectId: string) : Promise<GetDeploymentsResponse> {
|
|
const { data } = await this.client.query({
|
|
query: getDeployments,
|
|
variables: {
|
|
projectId
|
|
}
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
async removeMember (memberId: string): Promise<RemoveMemberResponse> {
|
|
const { data } = await this.client.mutate({
|
|
mutation: removeMember,
|
|
variables: {
|
|
memberId
|
|
}
|
|
});
|
|
|
|
return data;
|
|
}
|
|
|
|
async getProjectMembers (projectId: string) : Promise<GetProjectMembersResponse> {
|
|
const { data } = await this.client.query({
|
|
query: getProjectMembers,
|
|
variables: {
|
|
projectId
|
|
}
|
|
});
|
|
|
|
return data;
|
|
}
|
|
}
|