mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
refactor(core-sdk): GraphQLService
This commit is contained in:
+2
-2
@@ -89,8 +89,8 @@ export class ServerConfigurationService {
|
||||
}
|
||||
|
||||
try {
|
||||
await this.graphQLService.gql.setDefaultNavigatorSettings({ settings: this.state.navigatorConfig });
|
||||
await this.graphQLService.gql.configureServer({ configuration: this.state.serverConfig });
|
||||
await this.graphQLService.sdk.setDefaultNavigatorSettings({ settings: this.state.navigatorConfig });
|
||||
await this.graphQLService.sdk.configureServer({ configuration: this.state.serverConfig });
|
||||
this.usersResource.refreshAllLazy();
|
||||
} catch (exception) {
|
||||
this.notificationService.logException(exception, 'Can\'t save server configuration');
|
||||
|
||||
@@ -48,7 +48,7 @@ export class DBObjectService extends CachedMapResource<string, DBObject> {
|
||||
}
|
||||
|
||||
private async loadFromChildren(parentId: string) {
|
||||
const { dbObjects } = await this.graphQLService.gql.getChildrenDBObjectInfo({
|
||||
const { dbObjects } = await this.graphQLService.sdk.getChildrenDBObjectInfo({
|
||||
navNodeId: parentId,
|
||||
});
|
||||
|
||||
@@ -64,7 +64,7 @@ export class DBObjectService extends CachedMapResource<string, DBObject> {
|
||||
}
|
||||
|
||||
private async loadDBObjectInfo(navNodeId: string): Promise<DBObject> {
|
||||
const { objectInfo: { object } } = await this.graphQLService.gql.getDBObjectInfo({
|
||||
const { objectInfo: { object } } = await this.graphQLService.sdk.getDBObjectInfo({
|
||||
navNodeId,
|
||||
});
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export class NavNodeInfoResource extends CachedMapResource<string, NavNode> {
|
||||
}
|
||||
|
||||
private async loadNodeInfo(nodePath: string): Promise<NavNode> {
|
||||
const { navNodeInfo } = await this.graphQLService.gql.navNodeInfo({
|
||||
const { navNodeInfo } = await this.graphQLService.sdk.navNodeInfo({
|
||||
nodePath,
|
||||
});
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ export class NavNodeManagerService extends Bootstrap {
|
||||
}
|
||||
|
||||
async refreshTree(navNodeId: string) {
|
||||
await this.graphQLService.gql.navRefreshNode({
|
||||
await this.graphQLService.sdk.navRefreshNode({
|
||||
nodePath: navNodeId,
|
||||
});
|
||||
this.markTreeOutdated(navNodeId);
|
||||
|
||||
@@ -212,7 +212,7 @@ export class NavTreeResource extends CachedMapResource<string, string[]> {
|
||||
}
|
||||
|
||||
private async loadNodeChildren(parentPath: string) {
|
||||
const { navNodeChildren, navNodeInfo } = await this.graphQLService.gql.navNodeChildren({
|
||||
const { navNodeChildren, navNodeInfo } = await this.graphQLService.sdk.navNodeChildren({
|
||||
parentPath,
|
||||
});
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ export class LogViewerService {
|
||||
|
||||
async loadLog(): Promise<ILogEntry[]> {
|
||||
const maxLogEntries = this.coreSettingsService.settings.getValue('app.logViewer.logBatchSize');
|
||||
const { log } = await this.graphQLService.gql.readSessionLog({
|
||||
const { log } = await this.graphQLService.sdk.readSessionLog({
|
||||
maxEntries: maxLogEntries,
|
||||
clearEntries: true,
|
||||
});
|
||||
|
||||
@@ -26,18 +26,18 @@ export class AuthInfoService {
|
||||
private sessionService: SessionService,
|
||||
) { }
|
||||
|
||||
get userInfo() {
|
||||
get userInfo(): UserAuthInfo | null {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
async login(provider: string, credentials: object): Promise<UserAuthInfo> {
|
||||
async login(provider: string, credentials: Record<string, string>): Promise<UserAuthInfo> {
|
||||
if (this.user) {
|
||||
throw new Error('User already logged in');
|
||||
}
|
||||
|
||||
const processedCredentials = await this.authProviderService.processCredentials(provider, credentials);
|
||||
|
||||
const { user } = await this.graphQLService.gql.authLogin({
|
||||
const { user } = await this.graphQLService.sdk.authLogin({
|
||||
provider,
|
||||
credentials: processedCredentials,
|
||||
});
|
||||
@@ -47,9 +47,9 @@ export class AuthInfoService {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
async logout() {
|
||||
async logout(): Promise<void> {
|
||||
if (this.user) {
|
||||
await this.graphQLService.gql.authLogout();
|
||||
await this.graphQLService.sdk.authLogout();
|
||||
this.user = null;
|
||||
await this.updateSession();
|
||||
}
|
||||
@@ -57,7 +57,7 @@ export class AuthInfoService {
|
||||
|
||||
async updateAuthInfo(): Promise<UserAuthInfo | null> {
|
||||
try {
|
||||
const { user } = await this.graphQLService.gql.getSessionUser();
|
||||
const { user } = await this.graphQLService.sdk.getSessionUser();
|
||||
this.user = user || null;
|
||||
} catch (exception) {
|
||||
this.notificationService.logException(exception, 'Can\'t load session user');
|
||||
|
||||
@@ -28,7 +28,7 @@ export class AuthProvidersResource extends CachedDataResource<AuthProvider[], nu
|
||||
}
|
||||
|
||||
protected async loader(key: null): Promise<AuthProvider[]> {
|
||||
const { providers } = await this.graphQLService.gql.getAuthProviders();
|
||||
const { providers } = await this.graphQLService.sdk.getAuthProviders();
|
||||
|
||||
this.markUpdated(key);
|
||||
return providers;
|
||||
|
||||
@@ -44,7 +44,7 @@ export class RolesResource extends CachedMapResource<string, AdminRoleInfo> {
|
||||
protected async loader(key: ResourceKey<string>): Promise<Map<string, AdminRoleInfo>> {
|
||||
const roleId = key === 'all' ? undefined : key as string;
|
||||
|
||||
const { roles } = await this.graphQLService.gql.getRolesList({ roleId });
|
||||
const { roles } = await this.graphQLService.sdk.getRolesList({ roleId });
|
||||
|
||||
if (key === 'all') {
|
||||
this.data.clear();
|
||||
|
||||
@@ -63,19 +63,19 @@ export class UsersResource extends CachedMapResource<string, AdminUserInfo> {
|
||||
return [];
|
||||
}
|
||||
|
||||
const { grantedConnections } = await this.graphQLService.gql.getUserGrantedConnections({ userId });
|
||||
const { grantedConnections } = await this.graphQLService.sdk.getUserGrantedConnections({ userId });
|
||||
|
||||
return grantedConnections;
|
||||
}
|
||||
|
||||
async setConnections(userId: string, connections: string[]) {
|
||||
await this.graphQLService.gql.setConnections({ userId, connections });
|
||||
await this.graphQLService.sdk.setConnections({ userId, connections });
|
||||
}
|
||||
|
||||
async create({
|
||||
userId, roles, credentials, grantedConnections,
|
||||
}: UserCreateOptions): Promise<AdminUserInfo> {
|
||||
const { user } = await this.graphQLService.gql.createUser({ userId });
|
||||
const { user } = await this.graphQLService.sdk.createUser({ userId });
|
||||
|
||||
try {
|
||||
await this.updateCredentials(userId, credentials);
|
||||
@@ -95,7 +95,7 @@ export class UsersResource extends CachedMapResource<string, AdminUserInfo> {
|
||||
}
|
||||
|
||||
async grantRole(userId: string, roleId: string, skipUpdate?: boolean) {
|
||||
await this.graphQLService.gql.grantUserRole({ userId, roleId });
|
||||
await this.graphQLService.sdk.grantUserRole({ userId, roleId });
|
||||
|
||||
if (!skipUpdate) {
|
||||
await this.refresh(userId);
|
||||
@@ -103,7 +103,7 @@ export class UsersResource extends CachedMapResource<string, AdminUserInfo> {
|
||||
}
|
||||
|
||||
async revokeRole(userId: string, roleId: string, skipUpdate?: boolean) {
|
||||
await this.graphQLService.gql.revokeUserRole({ userId, roleId });
|
||||
await this.graphQLService.sdk.revokeUserRole({ userId, roleId });
|
||||
|
||||
if (!skipUpdate) {
|
||||
await this.refresh(userId);
|
||||
@@ -114,7 +114,7 @@ export class UsersResource extends CachedMapResource<string, AdminUserInfo> {
|
||||
const provider = 'local';
|
||||
const processedCredentials = await this.authProviderService.processCredentials(provider, credentials);
|
||||
|
||||
await this.graphQLService.gql.setUserCredentials({
|
||||
await this.graphQLService.sdk.setUserCredentials({
|
||||
providerId: provider,
|
||||
userId,
|
||||
credentials: processedCredentials,
|
||||
@@ -128,7 +128,7 @@ export class UsersResource extends CachedMapResource<string, AdminUserInfo> {
|
||||
throw new Error('You can\'t delete current logged user');
|
||||
}
|
||||
if (!this.isNew(key.list[i])) {
|
||||
await this.graphQLService.gql.deleteUser({ userId: key.list[i] });
|
||||
await this.graphQLService.sdk.deleteUser({ userId: key.list[i] });
|
||||
}
|
||||
this.data.delete(key.list[i]);
|
||||
}
|
||||
@@ -137,7 +137,7 @@ export class UsersResource extends CachedMapResource<string, AdminUserInfo> {
|
||||
throw new Error('You can\'t delete current logged user');
|
||||
}
|
||||
if (!this.isNew(key)) {
|
||||
await this.graphQLService.gql.deleteUser({ userId: key });
|
||||
await this.graphQLService.sdk.deleteUser({ userId: key });
|
||||
}
|
||||
this.data.delete(key);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ export class UsersResource extends CachedMapResource<string, AdminUserInfo> {
|
||||
protected async loader(key: ResourceKey<string>): Promise<Map<string, AdminUserInfo>> {
|
||||
const userId = key === 'all' ? undefined : key as string;
|
||||
|
||||
const { users } = await this.graphQLService.gql.getUsersList({ userId });
|
||||
const { users } = await this.graphQLService.sdk.getUsersList({ userId });
|
||||
|
||||
if (key === 'all') {
|
||||
this.data.clear();
|
||||
|
||||
@@ -80,14 +80,14 @@ export class ConnectionsResource extends CachedMapResource<string, ConnectionInf
|
||||
}
|
||||
|
||||
async searchDatabases(hosts: string[]) {
|
||||
const { databases } = await this.graphQLService.gql.searchDatabases({ hosts });
|
||||
const { databases } = await this.graphQLService.sdk.searchDatabases({ hosts });
|
||||
|
||||
return databases;
|
||||
}
|
||||
|
||||
async create(config: ConnectionConfig) {
|
||||
const { connection } = await this.graphQLService.gql.createConnectionConfiguration({ config });
|
||||
await this.graphQLService.gql.refreshSessionConnections();
|
||||
const { connection } = await this.graphQLService.sdk.createConnectionConfiguration({ config });
|
||||
await this.graphQLService.sdk.refreshSessionConnections();
|
||||
|
||||
const newConnection: ConnectionNew = {
|
||||
...connection as ConnectionInfo,
|
||||
@@ -99,20 +99,20 @@ export class ConnectionsResource extends CachedMapResource<string, ConnectionInf
|
||||
}
|
||||
|
||||
async test(config: ConnectionConfig): Promise<void> {
|
||||
await this.graphQLService.gql.testConnection({
|
||||
await this.graphQLService.sdk.testConnection({
|
||||
config,
|
||||
});
|
||||
}
|
||||
|
||||
async update(id: string, config: ConnectionConfig) {
|
||||
await this.performUpdate(id, () => this.updateConnection(id, config));
|
||||
await this.graphQLService.gql.refreshSessionConnections();
|
||||
await this.graphQLService.sdk.refreshSessionConnections();
|
||||
return this.get(id)!;
|
||||
}
|
||||
|
||||
async delete(key: ResourceKey<string>) {
|
||||
await this.performUpdate(key, () => this.deleteConnectionTask(key));
|
||||
await this.graphQLService.gql.refreshSessionConnections();
|
||||
await this.graphQLService.sdk.refreshSessionConnections();
|
||||
}
|
||||
|
||||
async loadAccessSubjects(connectionId: string): Promise<AdminConnectionGrantInfo[]> {
|
||||
@@ -120,17 +120,17 @@ export class ConnectionsResource extends CachedMapResource<string, ConnectionInf
|
||||
return [];
|
||||
}
|
||||
|
||||
const { subjects } = await this.graphQLService.gql.getConnectionAccess({ connectionId });
|
||||
const { subjects } = await this.graphQLService.sdk.getConnectionAccess({ connectionId });
|
||||
|
||||
return subjects;
|
||||
}
|
||||
|
||||
async setAccessSubjects(connectionId: string, subjects: string[]) {
|
||||
await this.graphQLService.gql.setConnectionAccess({ connectionId, subjects });
|
||||
await this.graphQLService.sdk.setConnectionAccess({ connectionId, subjects });
|
||||
}
|
||||
|
||||
protected async loader(key: ResourceKey<string>): Promise<Map<string, ConnectionInfo>> {
|
||||
const { connections } = await this.graphQLService.gql.getConnections();
|
||||
const { connections } = await this.graphQLService.sdk.getConnections();
|
||||
this.data.clear();
|
||||
|
||||
for (const connection of connections) {
|
||||
@@ -171,12 +171,12 @@ export class ConnectionsResource extends CachedMapResource<string, ConnectionInf
|
||||
this.data.delete(connectionId);
|
||||
|
||||
if (!isNew) {
|
||||
await this.graphQLService.gql.deleteConnectionConfiguration({ id: connectionId });
|
||||
await this.graphQLService.sdk.deleteConnectionConfiguration({ id: connectionId });
|
||||
}
|
||||
}
|
||||
|
||||
private async updateConnection(id: string, config: ConnectionConfig) {
|
||||
const { connection } = await this.graphQLService.gql.updateConnectionConfiguration({ id, config });
|
||||
const { connection } = await this.graphQLService.sdk.updateConnectionConfiguration({ id, config });
|
||||
|
||||
this.set(id, connection as ConnectionInfo);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export class ConnectionInfoResource extends CachedMapResource<string, Connection
|
||||
}
|
||||
|
||||
async createFromTemplate(templateId: string): Promise<Connection> {
|
||||
const { connection } = await this.graphQLService.gql.createConnectionFromTemplate({ templateId });
|
||||
const { connection } = await this.graphQLService.sdk.createConnectionFromTemplate({ templateId });
|
||||
this.set(connection.id, connection);
|
||||
|
||||
return this.get(connection.id)!;
|
||||
@@ -61,7 +61,7 @@ export class ConnectionInfoResource extends CachedMapResource<string, Connection
|
||||
|
||||
async deleteConnection(connectionId: string) {
|
||||
await this.performUpdate(connectionId, async () => {
|
||||
await this.graphQLService.gql.deleteConnection({ id: connectionId });
|
||||
await this.graphQLService.sdk.deleteConnection({ id: connectionId });
|
||||
});
|
||||
this.delete(connectionId);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ export class ConnectionInfoResource extends CachedMapResource<string, Connection
|
||||
}
|
||||
|
||||
protected async loader(connectionId: string): Promise<Map<string, Connection>> {
|
||||
const { connection } = await this.graphQLService.gql.connectionInfo({ id: connectionId });
|
||||
const { connection } = await this.graphQLService.sdk.connectionInfo({ id: connectionId });
|
||||
|
||||
const oldConnection = this.get(connectionId) || {};
|
||||
this.set(connectionId, { ...oldConnection, ...connection });
|
||||
@@ -104,19 +104,19 @@ export class ConnectionInfoResource extends CachedMapResource<string, Connection
|
||||
}
|
||||
|
||||
private async getAuthProperties(id: string): Promise<ObjectPropertyInfo[]> {
|
||||
const { connection: { authProperties } } = await this.graphQLService.gql.connectionAuthProperties({ id });
|
||||
const { connection: { authProperties } } = await this.graphQLService.sdk.connectionAuthProperties({ id });
|
||||
|
||||
return authProperties;
|
||||
}
|
||||
|
||||
private async initConnection(id: string, credentials?: any): Promise<Connection> {
|
||||
const { connection } = await this.graphQLService.gql.initConnection({ id, credentials });
|
||||
const { connection } = await this.graphQLService.sdk.initConnection({ id, credentials });
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
private async closeConnection(id: string): Promise<Connection> {
|
||||
const { connection } = await this.graphQLService.gql.closeConnection({ id });
|
||||
const { connection } = await this.graphQLService.sdk.closeConnection({ id });
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export class ContainerResource extends CachedDataResource<Map<string, ObjectCont
|
||||
}
|
||||
|
||||
protected async loader({ connectionId, catalogId }: ObjectContainerParams): Promise<Map<string, ObjectContainer[]>> {
|
||||
const { navGetStructContainers } = await this.graphQLService.gql.navGetStructContainers({
|
||||
const { navGetStructContainers } = await this.graphQLService.sdk.navGetStructContainers({
|
||||
connectionId,
|
||||
catalogId,
|
||||
});
|
||||
|
||||
@@ -64,7 +64,7 @@ export class DBDriverResource extends CachedMapResource<string, DBDriver> {
|
||||
}
|
||||
|
||||
protected async loader(key: string): Promise<Map<string, DBDriver>> {
|
||||
const { driverList } = await this.graphQLService.gql.driverList();
|
||||
const { driverList } = await this.graphQLService.sdk.driverList();
|
||||
|
||||
this.data.clear();
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export class DatabaseAuthModelsResource extends CachedMapResource<string, Databa
|
||||
}
|
||||
|
||||
protected async loader(key: string): Promise<Map<string, DatabaseAuthModel>> {
|
||||
const { models } = await this.graphQLService.gql.getAuthModels();
|
||||
const { models } = await this.graphQLService.sdk.getAuthModels();
|
||||
|
||||
this.set(resourceKeyList(models.map(model => model.id)), models);
|
||||
this.markUpdated(key);
|
||||
|
||||
@@ -18,7 +18,7 @@ export class DriverPropertiesService {
|
||||
}
|
||||
|
||||
async loadDriverProperties(driverId: string): Promise<ObjectPropertyInfo[]> {
|
||||
const response = await this.graphQLService.gql.driverProperties({
|
||||
const response = await this.graphQLService.sdk.driverProperties({
|
||||
driverId,
|
||||
});
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ export class LocalizationService extends Bootstrap {
|
||||
if (key === this.settings.language) {
|
||||
return;
|
||||
}
|
||||
const response = await this.graphQLService.gql.changeSessionLanguage({ locale: key });
|
||||
const response = await this.graphQLService.sdk.changeSessionLanguage({ locale: key });
|
||||
this.setLocale(key);
|
||||
if (response.changeSessionLanguage) {
|
||||
window.location.reload();
|
||||
|
||||
@@ -30,7 +30,7 @@ export class PermissionsResource extends CachedDataResource<Set<string>, null> {
|
||||
}
|
||||
|
||||
protected async loader(key: null): Promise<Set<string>> {
|
||||
const { permissions } = await this.graphQLService.gql.sessionPermissions();
|
||||
const { permissions } = await this.graphQLService.sdk.sessionPermissions();
|
||||
|
||||
this.data.clear();
|
||||
for (const permission of permissions) {
|
||||
|
||||
@@ -26,7 +26,7 @@ export class ServerConfigResource extends CachedDataResource<ServerConfig | null
|
||||
}
|
||||
|
||||
protected async loader(key: null): Promise<ServerConfig> {
|
||||
const { serverConfig } = await this.graphQLService.gql.serverConfig();
|
||||
const { serverConfig } = await this.graphQLService.sdk.serverConfig();
|
||||
|
||||
this.markUpdated(key);
|
||||
return serverConfig;
|
||||
|
||||
@@ -35,7 +35,7 @@ export class SessionResource extends CachedDataResource<SessionState | null, nul
|
||||
}
|
||||
|
||||
protected async loader(key: null): Promise<SessionState> {
|
||||
const { session } = await this.graphQLService.gql.openSession();
|
||||
const { session } = await this.graphQLService.sdk.openSession();
|
||||
|
||||
this.markUpdated(key);
|
||||
return session;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* cloudbeaver - Cloud Database Manager
|
||||
* Copyright (C) 2020 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0.
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { GraphQLClient } from 'graphql-request';
|
||||
import { Variables, ClientError } from 'graphql-request/dist/src/types';
|
||||
|
||||
import { GQLError } from './GQLError';
|
||||
import { IResponseInterceptor } from './IResponseInterceptor';
|
||||
|
||||
export class CustomGraphQLClient extends GraphQLClient {
|
||||
private interceptors: IResponseInterceptor[] = [];
|
||||
|
||||
constructor(endpoint: string) {
|
||||
super(endpoint);
|
||||
}
|
||||
|
||||
registerInterceptor(interceptor: IResponseInterceptor): void {
|
||||
this.interceptors.push(interceptor);
|
||||
}
|
||||
|
||||
request<T extends any>(query: string, variables?: Variables): Promise<T> {
|
||||
return this.interceptors.reduce(
|
||||
(accumulator, interceptor) => interceptor(accumulator),
|
||||
this.overrideRequest<T>(query, variables)
|
||||
);
|
||||
}
|
||||
|
||||
private async overrideRequest<T>(query: string, variables?: Variables): Promise<T> {
|
||||
try {
|
||||
const response = await this.rawRequest<T>(query, variables);
|
||||
|
||||
// TODO: seems here can be undefined
|
||||
return response.data as T;
|
||||
} catch (error) {
|
||||
if (isClientError(error)) {
|
||||
throw new GQLError(error);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isClientError(obj: any): obj is ClientError {
|
||||
// in es5 build `instanceof ClientError` always false, so we try to determine by checking response property
|
||||
return obj instanceof ClientError || obj.response;
|
||||
}
|
||||
@@ -6,55 +6,26 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { GraphQLClient } from 'graphql-request';
|
||||
import { Variables, ClientError } from 'graphql-request/dist/src/types';
|
||||
|
||||
import { injectable } from '@cloudbeaver/core-di';
|
||||
|
||||
import { CustomGraphQLClient } from './CustomGraphQLClient';
|
||||
import { EnvironmentService } from './EnvironmentService';
|
||||
import { GQLError } from './GQLError';
|
||||
import { IResponseInterceptor } from './IResponseInterceptor';
|
||||
import { getSdk } from './sdk';
|
||||
|
||||
@injectable()
|
||||
export class GraphQLService {
|
||||
gql: ReturnType<typeof getSdk>
|
||||
private client: GraphQLClient;
|
||||
sdk: ReturnType<typeof getSdk>
|
||||
|
||||
private interceptors: IResponseInterceptor[] = [];
|
||||
private client: CustomGraphQLClient;
|
||||
|
||||
constructor(private environmentService: EnvironmentService) {
|
||||
const gqlEndpoint = this.environmentService.gqlEndpoint;
|
||||
this.client = new GraphQLClient(gqlEndpoint);
|
||||
this.gql = getSdk({ ...this.client, request: this.interceptedRequest.bind(this) } as any);
|
||||
this.client = new CustomGraphQLClient(gqlEndpoint);
|
||||
this.sdk = getSdk(this.client);
|
||||
}
|
||||
|
||||
registerInterceptor(interceptor: IResponseInterceptor): void {
|
||||
this.interceptors.push(interceptor);
|
||||
}
|
||||
|
||||
private interceptedRequest(query: string, variables?: Variables) {
|
||||
return this.interceptors.reduce(
|
||||
(accumulator, interceptor) => interceptor(accumulator),
|
||||
this.overrideRequest(query, variables)
|
||||
);
|
||||
}
|
||||
|
||||
private async overrideRequest(query: string, variables?: Variables) {
|
||||
try {
|
||||
const response = await this.client.rawRequest(query, variables);
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (isClientError(error)) {
|
||||
throw new GQLError(error);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
this.client.registerInterceptor(interceptor);
|
||||
}
|
||||
}
|
||||
|
||||
function isClientError(obj: any): obj is ClientError {
|
||||
// in es5 build `instanceof ClientError` always false, so we try to determine by checking response property
|
||||
return obj instanceof ClientError || obj.response;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
export * from './CachedDataResource';
|
||||
export * from './GraphQLService';
|
||||
export * from './EnvironmentService';
|
||||
export * from './sdk';
|
||||
export * from './GQLError';
|
||||
export * from './ServerInternalError';
|
||||
export * from './CachedResource';
|
||||
export * from './CachedMapResource';
|
||||
export * from './CachedResource';
|
||||
export * from './CustomGraphQLClient';
|
||||
export * from './EnvironmentService';
|
||||
export * from './EServerErrorCode';
|
||||
export * from './GQLError';
|
||||
export * from './GQLErrorCatcher';
|
||||
export * from './GraphQLService';
|
||||
export * from './sdk';
|
||||
export * from './ServerInternalError';
|
||||
|
||||
@@ -20,7 +20,7 @@ export class CustomConnectionService {
|
||||
}
|
||||
|
||||
async createConnectionAsync(config: ConnectionConfig): Promise<Connection> {
|
||||
const response = await this.graphQLService.gql.createConnection({
|
||||
const response = await this.graphQLService.sdk.createConnection({
|
||||
config,
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ export class CustomConnectionService {
|
||||
}
|
||||
|
||||
async testConnectionAsync(config: ConnectionConfig): Promise<void> {
|
||||
await this.graphQLService.gql.testConnection({
|
||||
await this.graphQLService.sdk.testConnection({
|
||||
config,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ export class TemplateConnectionsResource extends CachedDataResource<Connection[]
|
||||
this.markUpdated(key);
|
||||
return [];
|
||||
}
|
||||
const { connections } = await this.graphQLService.gql.getTemplateConnections();
|
||||
const { connections } = await this.graphQLService.sdk.getTemplateConnections();
|
||||
this.markUpdated(key);
|
||||
return connections;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export class DataExportProcessService {
|
||||
try {
|
||||
const dataFileId = process.process.getPayload();
|
||||
if (dataFileId) {
|
||||
await this.graphQLService.gql.removeDataTransferFile({ dataFileId });
|
||||
await this.graphQLService.sdk.removeDataTransferFile({ dataFileId });
|
||||
}
|
||||
} catch (exception) {
|
||||
this.notificationService.logException(exception, 'Error occurred while deleting file');
|
||||
|
||||
@@ -26,7 +26,7 @@ export class DataTransferProcessorsResource extends CachedDataResource<Map<strin
|
||||
}
|
||||
|
||||
protected async loader(key: null) {
|
||||
const { processors } = await this.graphQLService.gql.getDataTransferProcessors();
|
||||
const { processors } = await this.graphQLService.sdk.getDataTransferProcessors();
|
||||
|
||||
this.data.clear();
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ export class ExportFromContainerProcess extends Deferred<string> {
|
||||
): Promise<string> {
|
||||
// start async task
|
||||
try {
|
||||
const { taskInfo } = await this.graphQLService.gql.exportDataFromContainer({
|
||||
const { taskInfo } = await this.graphQLService.sdk.exportDataFromContainer({
|
||||
connectionId,
|
||||
containerNodePath,
|
||||
parameters,
|
||||
@@ -80,7 +80,7 @@ export class ExportFromContainerProcess extends Deferred<string> {
|
||||
}
|
||||
// run the first check immediately because usually the query execution is fast
|
||||
try {
|
||||
const { taskInfo } = await this.graphQLService.gql.getAsyncTaskInfo({
|
||||
const { taskInfo } = await this.graphQLService.sdk.getAsyncTaskInfo({
|
||||
taskId: this.taskId,
|
||||
removeOnFinish: false,
|
||||
});
|
||||
@@ -104,7 +104,7 @@ export class ExportFromContainerProcess extends Deferred<string> {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this.graphQLService.gql.asyncTaskCancel({ taskId });
|
||||
await this.graphQLService.sdk.asyncTaskCancel({ taskId });
|
||||
this.isCancelConfirmed = true;
|
||||
} catch (e) {
|
||||
if (this.getState() === EDeferredState.CANCELLING) {
|
||||
@@ -131,7 +131,7 @@ export class ExportFromContainerProcess extends Deferred<string> {
|
||||
}
|
||||
// task execution successful
|
||||
this.toResolved(taskInfo.taskResult);
|
||||
await this.graphQLService.gql.getAsyncTaskInfo({ taskId: taskInfo.id, removeOnFinish: true });
|
||||
await this.graphQLService.sdk.getAsyncTaskInfo({ taskId: taskInfo.id, removeOnFinish: true });
|
||||
}
|
||||
|
||||
private onError(error: Error, status?: string) {
|
||||
|
||||
@@ -36,7 +36,7 @@ export class ExportFromResultsProcess extends Deferred<string> {
|
||||
): Promise<string> {
|
||||
// start async task
|
||||
try {
|
||||
const { taskInfo } = await this.graphQLService.gql.exportDataFromResults({
|
||||
const { taskInfo } = await this.graphQLService.sdk.exportDataFromResults({
|
||||
connectionId,
|
||||
contextId,
|
||||
resultsId,
|
||||
@@ -82,7 +82,7 @@ export class ExportFromResultsProcess extends Deferred<string> {
|
||||
}
|
||||
// run the first check immediately because usually the query execution is fast
|
||||
try {
|
||||
const { taskInfo } = await this.graphQLService.gql.getAsyncTaskInfo({
|
||||
const { taskInfo } = await this.graphQLService.sdk.getAsyncTaskInfo({
|
||||
taskId: this.taskId,
|
||||
removeOnFinish: false,
|
||||
});
|
||||
@@ -106,7 +106,7 @@ export class ExportFromResultsProcess extends Deferred<string> {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this.graphQLService.gql.asyncTaskCancel({ taskId });
|
||||
await this.graphQLService.sdk.asyncTaskCancel({ taskId });
|
||||
this.isCancelConfirmed = true;
|
||||
} catch (e) {
|
||||
if (this.getState() === EDeferredState.CANCELLING) {
|
||||
@@ -133,7 +133,7 @@ export class ExportFromResultsProcess extends Deferred<string> {
|
||||
}
|
||||
// task execution successful
|
||||
this.toResolved(taskInfo.taskResult);
|
||||
await this.graphQLService.gql.getAsyncTaskInfo({ taskId: taskInfo.id, removeOnFinish: true });
|
||||
await this.graphQLService.sdk.getAsyncTaskInfo({ taskId: taskInfo.id, removeOnFinish: true });
|
||||
}
|
||||
|
||||
private onError(error: Error, status?: string) {
|
||||
|
||||
@@ -55,7 +55,7 @@ export class DataViewerTableService {
|
||||
defaultSchema?: string
|
||||
): Promise<IExecutionContext> {
|
||||
|
||||
const response = await this.graphQLService.gql.sqlContextCreate({
|
||||
const response = await this.graphQLService.sdk.sqlContextCreate({
|
||||
connectionId,
|
||||
defaultCatalog,
|
||||
defaultSchema,
|
||||
@@ -77,7 +77,7 @@ export class DataViewerTableService {
|
||||
throw new Error('It is expected that data.sqlContextParams was set after first fetch');
|
||||
}
|
||||
|
||||
const response = await this.graphQLService.gql.updateResultsDataBatch({
|
||||
const response = await this.graphQLService.sdk.updateResultsDataBatch({
|
||||
connectionId: data.executionContext.connectionId,
|
||||
contextId: data.executionContext.contextId,
|
||||
resultsId: data.resultId,
|
||||
@@ -111,7 +111,7 @@ export class DataViewerTableService {
|
||||
model.executionContext = executionContext;
|
||||
}
|
||||
|
||||
const { readDataFromContainer } = await this.graphQLService.gql.readDataFromContainer({
|
||||
const { readDataFromContainer } = await this.graphQLService.sdk.readDataFromContainer({
|
||||
connectionId: model.executionContext.connectionId,
|
||||
contextId: model.executionContext.contextId,
|
||||
containerNodePath: model.containerNodePath,
|
||||
|
||||
@@ -37,7 +37,7 @@ export class DdlViewerService {
|
||||
}
|
||||
|
||||
private async fetchDdlMetadata(nodeId: string): Promise<string> {
|
||||
const response = await this.graphQLService.gql.metadataGetNodeDDL({ nodeId });
|
||||
const response = await this.graphQLService.sdk.metadataGetNodeDDL({ nodeId });
|
||||
return response.metadataGetNodeDDL || '';
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export class SqlDialectInfoService {
|
||||
async loadSqlDialectInfo(connectionId: string): Promise<SqlDialectInfo | undefined> {
|
||||
if (!this.dialectInfo.has(connectionId)) {
|
||||
try {
|
||||
const result = await this.graphQLService.gql.querySqlDialectInfo({ connectionId });
|
||||
const result = await this.graphQLService.sdk.querySqlDialectInfo({ connectionId });
|
||||
this.dialectInfo.set(connectionId, result.dialect!);
|
||||
} catch (error) {
|
||||
this.notificationService.logException(error, 'Failed to load SqlDialectInfo');
|
||||
|
||||
@@ -22,7 +22,7 @@ export class SqlEditorService {
|
||||
cursor: number
|
||||
): Promise<QuerySqlCompletionProposalsQuery['sqlCompletionProposals'] | null> {
|
||||
|
||||
const result = await this.gql.gql.querySqlCompletionProposals({
|
||||
const result = await this.gql.sdk.querySqlCompletionProposals({
|
||||
connectionId,
|
||||
contextId,
|
||||
query,
|
||||
|
||||
@@ -235,7 +235,7 @@ export class SqlEditorTabService {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this.gql.gql.sqlContextDestroy({ connectionId, contextId });
|
||||
await this.gql.sdk.sqlContextDestroy({ connectionId, contextId });
|
||||
} catch (exception) {
|
||||
this.notificationService.logException(exception, `Failed to destroy SQL-context ${contextId}`, true);
|
||||
}
|
||||
@@ -253,7 +253,7 @@ export class SqlEditorTabService {
|
||||
defaultSchema?: string
|
||||
): Promise<IExecutionContext> {
|
||||
|
||||
const response = await this.gql.gql.sqlContextCreate({
|
||||
const response = await this.gql.sdk.sqlContextCreate({
|
||||
connectionId,
|
||||
defaultCatalog,
|
||||
defaultSchema,
|
||||
@@ -275,7 +275,7 @@ export class SqlEditorTabService {
|
||||
defaultCatalog?: string,
|
||||
defaultSchema?: string
|
||||
) {
|
||||
await this.gql.gql.sqlContextSetDefaults({
|
||||
await this.gql.sdk.sqlContextSetDefaults({
|
||||
connectionId,
|
||||
contextId,
|
||||
defaultCatalog,
|
||||
|
||||
@@ -109,7 +109,7 @@ export class SQLQueryExecutionProcess extends Deferred<SqlExecuteInfo> {
|
||||
sqlQueryParams: ISqlQueryParams,
|
||||
filter: SqlDataFilter,
|
||||
): Promise<AsyncTaskInfo> {
|
||||
const { taskInfo } = await this.graphQLService.gql.asyncSqlExecuteQuery({
|
||||
const { taskInfo } = await this.graphQLService.sdk.asyncSqlExecuteQuery({
|
||||
connectionId: sqlQueryParams.connectionId,
|
||||
contextId: sqlQueryParams.contextId,
|
||||
query: sqlQueryParams.query,
|
||||
@@ -119,12 +119,12 @@ export class SQLQueryExecutionProcess extends Deferred<SqlExecuteInfo> {
|
||||
}
|
||||
|
||||
private async getQueryStatusAsync(taskId: string): Promise<AsyncTaskInfo> {
|
||||
const { taskInfo } = await this.graphQLService.gql.getAsyncTaskInfo({ taskId, removeOnFinish: false });
|
||||
const { taskInfo } = await this.graphQLService.sdk.getAsyncTaskInfo({ taskId, removeOnFinish: false });
|
||||
return taskInfo;
|
||||
}
|
||||
|
||||
private async cancelQueryAsync(taskId: string): Promise<void> {
|
||||
await this.graphQLService.gql.asyncTaskCancel({ taskId });
|
||||
await this.graphQLService.sdk.asyncTaskCancel({ taskId });
|
||||
}
|
||||
|
||||
private async applyResult(taskInfo: AsyncTaskInfo) {
|
||||
@@ -140,9 +140,9 @@ export class SQLQueryExecutionProcess extends Deferred<SqlExecuteInfo> {
|
||||
}
|
||||
try {
|
||||
// task execution successful
|
||||
const { result } = await this.graphQLService.gql.getSqlExecuteTaskResults({ taskId: taskInfo.id });
|
||||
const { result } = await this.graphQLService.sdk.getSqlExecuteTaskResults({ taskId: taskInfo.id });
|
||||
this.toResolved(result);
|
||||
await this.graphQLService.gql.getAsyncTaskInfo({ taskId: taskInfo.id, removeOnFinish: true });
|
||||
await this.graphQLService.sdk.getAsyncTaskInfo({ taskId: taskInfo.id, removeOnFinish: true });
|
||||
} catch (exception) {
|
||||
this.onError(new Error('Tasks execution returns no result'), exception);
|
||||
}
|
||||
|
||||
@@ -7,24 +7,15 @@
|
||||
*/
|
||||
|
||||
import { injectable } from '@cloudbeaver/core-di';
|
||||
import { NotificationService } from '@cloudbeaver/core-events';
|
||||
import {
|
||||
GraphQLService,
|
||||
SqlExecuteInfo,
|
||||
SqlDataFilter,
|
||||
} from '@cloudbeaver/core-sdk';
|
||||
import { GraphQLService, SqlExecuteInfo } from '@cloudbeaver/core-sdk';
|
||||
import { IRequestDataResult, RowDiff } from '@cloudbeaver/plugin-data-viewer';
|
||||
|
||||
import { ISqlQueryParams } from '../ISqlEditorTabState';
|
||||
import { SQLQueryExecutionProcess } from './SQLQueryExecutionProcess';
|
||||
|
||||
@injectable()
|
||||
export class SqlResultService {
|
||||
|
||||
constructor(
|
||||
private graphQLService: GraphQLService,
|
||||
private notificationService: NotificationService
|
||||
) { }
|
||||
constructor(private graphQLService: GraphQLService) { }
|
||||
|
||||
async saveChanges(
|
||||
sqlQueryParams: ISqlQueryParams,
|
||||
@@ -32,7 +23,7 @@ export class SqlResultService {
|
||||
diff: RowDiff[]
|
||||
): Promise<SqlExecuteInfo> {
|
||||
|
||||
const response = await this.graphQLService.gql.updateResultsDataBatch({
|
||||
const response = await this.graphQLService.sdk.updateResultsDataBatch({
|
||||
connectionId: sqlQueryParams.connectionId,
|
||||
contextId: sqlQueryParams.contextId,
|
||||
resultsId: resultId,
|
||||
|
||||
Reference in New Issue
Block a user