2024-01-23 11:47:02 +00:00
|
|
|
import { ApolloClient, DefaultOptions, InMemoryCache, NormalizedCacheObject } from '@apollo/client';
|
2024-01-17 08:52:15 +00:00
|
|
|
|
2024-01-29 11:01:03 +00:00
|
|
|
import { getUser, getOrganizations, getDeployments, getProjectMembers, searchProjects, getEnvironmentVariables, getProject, getProjectsInOrganization } from './queries';
|
2024-01-29 12:09:51 +00:00
|
|
|
import { AddEnvironmentVariableInput, AddEnvironmentVariablesResponse, GetDeploymentsResponse, GetEnvironmentVariablesResponse, GetOrganizationsResponse, GetProjectMembersResponse, SearchProjectsResponse, GetUserResponse, RemoveMemberResponse, UpdateDeploymentToProdResponse, GetProjectResponse, UpdateProjectResponse, UpdateProjectInput, RedeployToProdResponse, DeleteProjectResponse, GetProjectsInOrganizationResponse, RollbackDeploymentResponse } from './types';
|
|
|
|
import { removeMember, addEnvironmentVariables, updateDeploymentToProd, updateProjectMutation, redeployToProd, deleteProject, rollbackDeployment } from './mutations';
|
2024-01-17 08:52:15 +00:00
|
|
|
|
|
|
|
export interface GraphQLConfig {
|
|
|
|
gqlEndpoint: string;
|
|
|
|
}
|
|
|
|
|
2024-01-23 11:47:02 +00:00
|
|
|
// TODO: check options
|
|
|
|
const defaultOptions: DefaultOptions = {
|
|
|
|
watchQuery: {
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'ignore'
|
|
|
|
},
|
|
|
|
query: {
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'all'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-01-17 08:52:15 +00:00
|
|
|
export class GQLClient {
|
|
|
|
private client: ApolloClient<NormalizedCacheObject>;
|
|
|
|
|
|
|
|
constructor (config: GraphQLConfig) {
|
|
|
|
this.client = new ApolloClient({
|
|
|
|
uri: config.gqlEndpoint,
|
2024-01-23 11:47:02 +00:00
|
|
|
cache: new InMemoryCache(),
|
|
|
|
defaultOptions
|
2024-01-17 08:52:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-23 11:47:02 +00:00
|
|
|
async getUser () : Promise<GetUserResponse> {
|
2024-01-17 08:52:15 +00:00
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getUser
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-18 04:34:02 +00:00
|
|
|
|
2024-01-25 11:08:40 +00:00
|
|
|
async getProject (projectId: string) : Promise<GetProjectResponse> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getProject,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-01-29 11:01:03 +00:00
|
|
|
async getProjectsInOrganization (organizationId: string) : Promise<GetProjectsInOrganizationResponse> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getProjectsInOrganization,
|
|
|
|
variables: {
|
|
|
|
organizationId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-01-23 11:47:02 +00:00
|
|
|
async getOrganizations () : Promise<GetOrganizationsResponse> {
|
2024-01-18 04:34:02 +00:00
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getOrganizations
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-18 12:20:50 +00:00
|
|
|
|
2024-01-23 11:47:02 +00:00
|
|
|
async getDeployments (projectId: string) : Promise<GetDeploymentsResponse> {
|
2024-01-18 12:20:50 +00:00
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getDeployments,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-23 11:47:02 +00:00
|
|
|
|
2024-01-25 05:14:51 +00:00
|
|
|
async getEnvironmentVariables (projectId: string) : Promise<GetEnvironmentVariablesResponse> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: getEnvironmentVariables,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-01-23 11:47:02 +00:00
|
|
|
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;
|
|
|
|
}
|
2024-01-24 14:47:43 +00:00
|
|
|
|
|
|
|
async searchProjects (searchText: string) : Promise<SearchProjectsResponse> {
|
|
|
|
const { data } = await this.client.query({
|
|
|
|
query: searchProjects,
|
|
|
|
variables: {
|
|
|
|
searchText
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-25 05:14:51 +00:00
|
|
|
|
|
|
|
async addEnvironmentVariables (projectId: string, environmentVariables: AddEnvironmentVariableInput[]): Promise<AddEnvironmentVariablesResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: addEnvironmentVariables,
|
|
|
|
variables: {
|
|
|
|
projectId,
|
|
|
|
environmentVariables
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-25 05:47:44 +00:00
|
|
|
|
|
|
|
async updateDeploymentToProd (deploymentId: string): Promise<UpdateDeploymentToProdResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: updateDeploymentToProd,
|
|
|
|
variables: {
|
|
|
|
deploymentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-25 11:08:40 +00:00
|
|
|
|
|
|
|
async updateProject (projectId: string, updateProject: UpdateProjectInput): Promise<UpdateProjectResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: updateProjectMutation,
|
|
|
|
variables: {
|
|
|
|
projectId,
|
|
|
|
updateProject
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-25 12:04:13 +00:00
|
|
|
|
|
|
|
async redeployToProd (deploymentId: string): Promise<RedeployToProdResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: redeployToProd,
|
|
|
|
variables: {
|
|
|
|
deploymentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-29 11:01:03 +00:00
|
|
|
|
|
|
|
async deleteProject (projectId: string): Promise<DeleteProjectResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: deleteProject,
|
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-29 12:09:51 +00:00
|
|
|
|
|
|
|
async rollbackDeployment (projectId: string, deploymentId: string): Promise<RollbackDeploymentResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: rollbackDeployment,
|
|
|
|
variables: {
|
|
|
|
projectId,
|
|
|
|
deploymentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-17 08:52:15 +00:00
|
|
|
}
|