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-02-14 06:46:01 +00:00
|
|
|
import * as queries from './queries';
|
|
|
|
import * as types from './types';
|
|
|
|
import * as mutations 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(),
|
2024-02-22 11:56:26 +00:00
|
|
|
defaultOptions,
|
|
|
|
credentials: 'include'
|
2024-01-17 08:52:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async getUser () : Promise<types.GetUserResponse> {
|
2024-01-17 08:52:15 +00:00
|
|
|
const { data } = await this.client.query({
|
2024-02-14 06:46:01 +00:00
|
|
|
query: queries.getUser
|
2024-01-17 08:52:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-18 04:34:02 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async getProject (projectId: string) : Promise<types.GetProjectResponse> {
|
2024-01-25 11:08:40 +00:00
|
|
|
const { data } = await this.client.query({
|
2024-02-14 06:46:01 +00:00
|
|
|
query: queries.getProject,
|
2024-01-25 11:08:40 +00:00
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async getProjectsInOrganization (organizationSlug: string) : Promise<types.GetProjectsInOrganizationResponse> {
|
2024-01-29 11:01:03 +00:00
|
|
|
const { data } = await this.client.query({
|
2024-02-14 06:46:01 +00:00
|
|
|
query: queries.getProjectsInOrganization,
|
2024-01-29 11:01:03 +00:00
|
|
|
variables: {
|
2024-02-07 13:11:54 +00:00
|
|
|
organizationSlug
|
2024-01-29 11:01:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async getOrganizations () : Promise<types.GetOrganizationsResponse> {
|
2024-01-18 04:34:02 +00:00
|
|
|
const { data } = await this.client.query({
|
2024-02-14 06:46:01 +00:00
|
|
|
query: queries.getOrganizations
|
2024-01-18 04:34:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-18 12:20:50 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async getDeployments (projectId: string) : Promise<types.GetDeploymentsResponse> {
|
2024-01-18 12:20:50 +00:00
|
|
|
const { data } = await this.client.query({
|
2024-02-14 06:46:01 +00:00
|
|
|
query: queries.getDeployments,
|
2024-01-18 12:20:50 +00:00
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-23 11:47:02 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async getEnvironmentVariables (projectId: string) : Promise<types.GetEnvironmentVariablesResponse> {
|
2024-01-25 05:14:51 +00:00
|
|
|
const { data } = await this.client.query({
|
2024-02-14 06:46:01 +00:00
|
|
|
query: queries.getEnvironmentVariables,
|
2024-01-25 05:14:51 +00:00
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async getProjectMembers (projectId: string) : Promise<types.GetProjectMembersResponse> {
|
2024-01-31 11:39:29 +00:00
|
|
|
const result = await this.client.query({
|
2024-02-14 06:46:01 +00:00
|
|
|
query: queries.getProjectMembers,
|
2024-01-23 11:47:02 +00:00
|
|
|
variables: {
|
2024-01-31 11:39:29 +00:00
|
|
|
projectId
|
2024-01-23 11:47:02 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-31 11:39:29 +00:00
|
|
|
return result.data;
|
2024-01-23 11:47:02 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async addProjectMember (projectId: string, data: types.AddProjectMemberInput) : Promise<types.AddProjectMemberResponse> {
|
2024-02-01 10:04:17 +00:00
|
|
|
const result = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.addProjectMember,
|
2024-02-01 10:04:17 +00:00
|
|
|
variables: {
|
|
|
|
projectId,
|
|
|
|
data
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result.data;
|
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async updateProjectMember (projectMemberId: string, data: types.UpdateProjectMemberInput): Promise<types.UpdateProjectMemberResponse> {
|
2024-01-31 11:39:29 +00:00
|
|
|
const result = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.updateProjectMember,
|
2024-01-23 11:47:02 +00:00
|
|
|
variables: {
|
2024-01-31 11:39:29 +00:00
|
|
|
projectMemberId,
|
|
|
|
data
|
2024-01-23 11:47:02 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-31 11:39:29 +00:00
|
|
|
return result.data;
|
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async removeProjectMember (projectMemberId: string): Promise<types.RemoveProjectMemberResponse> {
|
2024-01-31 11:39:29 +00:00
|
|
|
const result = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.removeProjectMember,
|
2024-01-31 11:39:29 +00:00
|
|
|
variables: {
|
|
|
|
projectMemberId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result.data;
|
2024-01-23 11:47:02 +00:00
|
|
|
}
|
2024-01-24 14:47:43 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async searchProjects (searchText: string) : Promise<types.SearchProjectsResponse> {
|
2024-01-24 14:47:43 +00:00
|
|
|
const { data } = await this.client.query({
|
2024-02-14 06:46:01 +00:00
|
|
|
query: queries.searchProjects,
|
2024-01-24 14:47:43 +00:00
|
|
|
variables: {
|
|
|
|
searchText
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-25 05:14:51 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async addEnvironmentVariables (projectId: string, data: types.AddEnvironmentVariableInput[]): Promise<types.AddEnvironmentVariablesResponse> {
|
2024-02-05 10:51:55 +00:00
|
|
|
const result = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.addEnvironmentVariables,
|
2024-01-25 05:14:51 +00:00
|
|
|
variables: {
|
|
|
|
projectId,
|
2024-02-05 10:51:55 +00:00
|
|
|
data
|
2024-01-25 05:14:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-05 10:51:55 +00:00
|
|
|
return result.data;
|
2024-01-25 05:14:51 +00:00
|
|
|
}
|
2024-01-25 05:47:44 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async updateEnvironmentVariable (environmentVariableId: string, data: types.UpdateEnvironmentVariableInput): Promise<types.UpdateEnvironmentVariableResponse> {
|
2024-02-05 10:51:55 +00:00
|
|
|
const result = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.updateEnvironmentVariable,
|
2024-01-31 05:06:22 +00:00
|
|
|
variables: {
|
|
|
|
environmentVariableId,
|
2024-02-05 10:51:55 +00:00
|
|
|
data
|
2024-01-31 05:06:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-05 10:51:55 +00:00
|
|
|
return result.data;
|
2024-01-31 05:06:22 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async removeEnvironmentVariable (environmentVariableId: string): Promise<types.RemoveEnvironmentVariableResponse> {
|
2024-01-31 05:06:22 +00:00
|
|
|
const { data } = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.removeEnvironmentVariable,
|
2024-01-31 05:06:22 +00:00
|
|
|
variables: {
|
|
|
|
environmentVariableId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async updateDeploymentToProd (deploymentId: string): Promise<types.UpdateDeploymentToProdResponse> {
|
2024-01-25 05:47:44 +00:00
|
|
|
const { data } = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.updateDeploymentToProd,
|
2024-01-25 05:47:44 +00:00
|
|
|
variables: {
|
|
|
|
deploymentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-25 11:08:40 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async addProject (organizationSlug: string, data: types.AddProjectInput): Promise<types.AddProjectResponse> {
|
2024-02-05 12:27:08 +00:00
|
|
|
const result = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.addProject,
|
2024-02-01 12:40:15 +00:00
|
|
|
variables: {
|
2024-02-07 13:11:54 +00:00
|
|
|
organizationSlug,
|
2024-02-05 12:27:08 +00:00
|
|
|
data
|
2024-02-01 12:40:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-05 12:27:08 +00:00
|
|
|
return result.data;
|
2024-02-01 12:40:15 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 12:05:02 +00:00
|
|
|
async updateProject (projectId: string, data: types.UpdateProjectInput): Promise<types.UpdateProjectResponse> {
|
|
|
|
const result = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.updateProjectMutation,
|
2024-01-25 11:08:40 +00:00
|
|
|
variables: {
|
|
|
|
projectId,
|
2024-02-14 12:05:02 +00:00
|
|
|
data
|
2024-01-30 08:31:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-14 12:05:02 +00:00
|
|
|
return result.data;
|
2024-01-30 08:31:09 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 12:05:02 +00:00
|
|
|
async updateDomain (domainId: string, data: types.UpdateDomainInput): Promise<types.UpdateDomainResponse> {
|
|
|
|
const result = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.updateDomainMutation,
|
2024-01-30 08:31:09 +00:00
|
|
|
variables: {
|
|
|
|
domainId,
|
2024-02-14 12:05:02 +00:00
|
|
|
data
|
2024-01-25 11:08:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-14 12:05:02 +00:00
|
|
|
return result.data;
|
2024-01-25 11:08:40 +00:00
|
|
|
}
|
2024-01-25 12:04:13 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async redeployToProd (deploymentId: string): Promise<types.RedeployToProdResponse> {
|
2024-01-25 12:04:13 +00:00
|
|
|
const { data } = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.redeployToProd,
|
2024-01-25 12:04:13 +00:00
|
|
|
variables: {
|
|
|
|
deploymentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-29 11:01:03 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async deleteProject (projectId: string): Promise<types.DeleteProjectResponse> {
|
2024-01-29 11:01:03 +00:00
|
|
|
const { data } = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.deleteProject,
|
2024-01-29 11:01:03 +00:00
|
|
|
variables: {
|
|
|
|
projectId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-29 12:09:51 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async deleteDomain (domainId: string): Promise<types.DeleteDomainResponse> {
|
2024-02-01 03:34:24 +00:00
|
|
|
const { data } = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.deleteDomain,
|
2024-02-01 03:34:24 +00:00
|
|
|
variables: {
|
|
|
|
domainId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async rollbackDeployment (projectId: string, deploymentId: string): Promise<types.RollbackDeploymentResponse> {
|
2024-01-29 12:09:51 +00:00
|
|
|
const { data } = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.rollbackDeployment,
|
2024-01-29 12:09:51 +00:00
|
|
|
variables: {
|
|
|
|
projectId,
|
|
|
|
deploymentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-03-27 16:58:56 +00:00
|
|
|
|
|
|
|
async deleteDeployment (deploymentId: string): Promise<types.DeleteDeploymentResponse> {
|
|
|
|
const { data } = await this.client.mutate({
|
|
|
|
mutation: mutations.deleteDeployment,
|
|
|
|
variables: {
|
|
|
|
deploymentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-29 12:48:43 +00:00
|
|
|
|
2024-02-14 12:05:02 +00:00
|
|
|
async addDomain (projectId: string, data: types.AddDomainInput): Promise<types.AddDomainResponse> {
|
|
|
|
const result = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.addDomain,
|
2024-01-29 12:48:43 +00:00
|
|
|
variables: {
|
|
|
|
projectId,
|
2024-02-14 12:05:02 +00:00
|
|
|
data
|
2024-01-29 12:48:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-14 12:05:02 +00:00
|
|
|
return result.data;
|
2024-01-29 12:48:43 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async getDomains (projectId: string, filter?: types.FilterDomainInput): Promise<types.GetDomainsResponse> {
|
2024-01-29 12:48:43 +00:00
|
|
|
const { data } = await this.client.query({
|
2024-02-14 06:46:01 +00:00
|
|
|
query: queries.getDomains,
|
2024-01-29 12:48:43 +00:00
|
|
|
variables: {
|
2024-02-06 08:48:06 +00:00
|
|
|
projectId,
|
|
|
|
filter
|
2024-01-29 12:48:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-30 14:20:53 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async authenticateGitHub (code: string): Promise<types.AuthenticateGitHubResponse> {
|
2024-01-30 14:20:53 +00:00
|
|
|
const { data } = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.authenticateGitHub,
|
2024-01-30 14:20:53 +00:00
|
|
|
variables: {
|
|
|
|
code
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-31 13:21:53 +00:00
|
|
|
|
2024-02-14 06:46:01 +00:00
|
|
|
async unauthenticateGithub (): Promise<types.UnauthenticateGitHubResponse> {
|
2024-01-31 13:21:53 +00:00
|
|
|
const { data } = await this.client.mutate({
|
2024-02-14 06:46:01 +00:00
|
|
|
mutation: mutations.unauthenticateGitHub
|
2024-01-31 13:21:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2024-01-17 08:52:15 +00:00
|
|
|
}
|