From 12789e2624bbc03dc469beb5f1391cbc8871629c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hornych?= Date: Fri, 13 Oct 2023 15:04:51 +0200 Subject: [PATCH] fix: evitaDB don't use kebab-case classifiers in API URLs --- .../editor/data-grid-console/evitaql-query-executor.ts | 6 +----- .../editor/data-grid-console/graphql-query-executor.ts | 10 +--------- src/services/editor/evitaql-console.service.ts | 6 +----- src/services/editor/graphql-console.service.ts | 8 ++------ src/services/evitadb-client.ts | 8 ++++---- src/services/lab.service.ts | 2 +- src/store/modules/lab.ts | 10 +++++++++- 7 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/services/editor/data-grid-console/evitaql-query-executor.ts b/src/services/editor/data-grid-console/evitaql-query-executor.ts index 65d4e846..6f3c7fe5 100644 --- a/src/services/editor/data-grid-console/evitaql-query-executor.ts +++ b/src/services/editor/data-grid-console/evitaql-query-executor.ts @@ -21,11 +21,7 @@ export class EvitaQLQueryExecutor extends QueryExecutor { } async executeQuery(dataPointer: DataGridDataPointer, query: string): Promise { - const urlCatalogName: string = (await this.labService.getCatalogSchema(dataPointer.connection, dataPointer.catalogName)) - .nameVariants - .kebabCase - - const result: Response = await this.evitaDBClient.queryEntities(dataPointer.connection, urlCatalogName, query) + const result: Response = await this.evitaDBClient.queryEntities(dataPointer.connection, dataPointer.catalogName, query) return { entities: result?.recordPage?.data.map((entity: any) => this.flattenEntity(entity)) || [], diff --git a/src/services/editor/data-grid-console/graphql-query-executor.ts b/src/services/editor/data-grid-console/graphql-query-executor.ts index f0409643..1c16a632 100644 --- a/src/services/editor/data-grid-console/graphql-query-executor.ts +++ b/src/services/editor/data-grid-console/graphql-query-executor.ts @@ -21,15 +21,7 @@ export class GraphQLQueryExecutor extends QueryExecutor { } async executeQuery(dataPointer: DataGridDataPointer, query: string): Promise { - const urlCatalogName: string = (await this.labService.getCatalogSchema(dataPointer.connection, dataPointer.catalogName)) - .nameVariants - .kebabCase - - const result = await this.graphQLClient.fetch( - dataPointer.connection, - `${urlCatalogName}`, - query - ) + const result = await this.graphQLClient.fetch(dataPointer.connection, dataPointer.catalogName, query) if (result.errors) { throw new QueryError(dataPointer.connection, result.errors) } diff --git a/src/services/editor/evitaql-console.service.ts b/src/services/editor/evitaql-console.service.ts index f735e2bc..847ac85b 100644 --- a/src/services/editor/evitaql-console.service.ts +++ b/src/services/editor/evitaql-console.service.ts @@ -22,13 +22,9 @@ export class EvitaQLConsoleService { */ // todo lho variables async executeEvitaQLQuery(dataPointer: EvitaQLDataPointer, query: string, variables?: object): Promise { - const urlCatalogName: string = (await this.labService.getCatalogSchema(dataPointer.connection, dataPointer.catalogName)) - .nameVariants - .kebabCase - let result: any try { - result = await this.evitaDBClient.queryEntities(dataPointer.connection, urlCatalogName, query) + result = await this.evitaDBClient.queryEntities(dataPointer.connection, dataPointer.catalogName, query) } catch (e: any) { if (e.name === 'QueryError') { result = e.error diff --git a/src/services/editor/graphql-console.service.ts b/src/services/editor/graphql-console.service.ts index ef94adbc..09c9a4ab 100644 --- a/src/services/editor/graphql-console.service.ts +++ b/src/services/editor/graphql-console.service.ts @@ -52,16 +52,12 @@ export class GraphQLConsoleService { if (instancePointer.instanceType === GraphQLInstanceType.SYSTEM) { path = 'system' } else { - const urlCatalogName: string = (await this.labService.getCatalogSchema(instancePointer.connection, instancePointer.catalogName)) - .nameVariants - .kebabCase - switch (instancePointer.instanceType) { case GraphQLInstanceType.DATA: - path = urlCatalogName + path = instancePointer.catalogName break case GraphQLInstanceType.SCHEMA: - path = `${urlCatalogName}/schema` + path = `${instancePointer.catalogName}/schema` break default: throw new UnexpectedError(instancePointer.connection, `Unsupported GraphQL instance type '${instancePointer.instanceType}'.`) } diff --git a/src/services/evitadb-client.ts b/src/services/evitadb-client.ts index 96299ebe..5a380d36 100644 --- a/src/services/evitadb-client.ts +++ b/src/services/evitadb-client.ts @@ -11,9 +11,9 @@ export class EvitaDBClient extends ApiClient { /** * Fetches schema from evitaDB server for specific catalog. */ - async getCatalogSchema(connection: EvitaDBConnection, urlCatalogName: string): Promise { + async getCatalogSchema(connection: EvitaDBConnection, catalogName: string): Promise { try { - return await this.httpClient.get(`${connection.labApiUrl}/schema/catalogs/${urlCatalogName}`) + return await this.httpClient.get(`${connection.labApiUrl}/schema/catalogs/${catalogName}`) .json() as CatalogSchema } catch (e: any) { throw this.handleCallError(e, connection) @@ -35,10 +35,10 @@ export class EvitaDBClient extends ApiClient { /** * Fetches entities with extra results from evitaDB server from specific catalog. */ - async queryEntities(connection: EvitaDBConnection, urlCatalogName: string, query: string): Promise { + async queryEntities(connection: EvitaDBConnection, catalogName: string, query: string): Promise { try { return await this.httpClient.post( - `${connection.labApiUrl}/data/catalogs/${urlCatalogName}/collections/query`, + `${connection.labApiUrl}/data/catalogs/${catalogName}/collections/query`, { headers: { 'Content-Type': 'application/json' diff --git a/src/services/lab.service.ts b/src/services/lab.service.ts index 934892b4..c1ee9ed4 100644 --- a/src/services/lab.service.ts +++ b/src/services/lab.service.ts @@ -194,7 +194,7 @@ export class LabService { private async fetchCatalogSchema(connection: EvitaDBConnection, catalogName: string): Promise { const catalog: Catalog = await this.getCatalog(connection, catalogName) - const fetchedCatalogSchema: CatalogSchema = await this.evitaDBClient.getCatalogSchema(connection, catalog.nameVariants.kebabCase) + const fetchedCatalogSchema: CatalogSchema = await this.evitaDBClient.getCatalogSchema(connection, catalog.name) this.store.commit( 'lab/putCatalogSchema', diff --git a/src/store/modules/lab.ts b/src/store/modules/lab.ts index 8eb1200c..d843fa5f 100644 --- a/src/store/modules/lab.ts +++ b/src/store/modules/lab.ts @@ -85,11 +85,19 @@ const state = (): LabState => { preconfiguredConnections.push(new EvitaDBConnection( 'demo', 'Demo', - false, + true, 'https://demo.evitadb.io/lab/api', 'https://demo.evitadb.io:5555/rest', 'https://demo.evitadb.io:5555/gql' )) + preconfiguredConnections.push(new EvitaDBConnection( + 'localhost', + 'Localhost', + true, + 'https://localhost:5555/lab/api', + 'https://localhost:5555/rest', + 'https://localhost:5555/gql' + )) } // initialize storage for the current instance