Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ FROM node:16-alpine

WORKDIR /app
COPY package.json .
COPY package-lock.json .
# COPY package-lock.json .

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting out the COPY package-lock.json . line.

Removing package-lock.json from the Docker build context can lead to non-deterministic builds because npm i will install the latest versions of dependencies, potentially introducing breaking changes. Consider using npm ci instead of npm i for more reliable builds, which requires package-lock.json.


RUN npm ci --include=dev
RUN npm i --include=dev

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing npm ci --include=dev to npm i --include=dev.

Switching from npm ci to npm i decreases the reproducibility of builds. npm ci ensures that the exact versions of dependencies specified in package-lock.json are installed, leading to more predictable and stable builds. If the goal is to update dependencies, consider doing so explicitly and committing the updated package-lock.json.


COPY tsconfig.json .
COPY nodemon.json .
Expand Down
47 changes: 47 additions & 0 deletions src/handlers/mutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
ColumnInsertFieldValue,
MutationRequest,
MutationResponse,
QueryRequest,
QueryResponse,
} from "@hasura/dc-api-types";
import { Config } from "../config";
import def from "ajv/dist/vocabularies/discriminator";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing def from ajv/dist/vocabularies/discriminator but not using it.

- import def from "ajv/dist/vocabularies/discriminator";

Remove the unused import to clean up the code and reduce confusion.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
import def from "ajv/dist/vocabularies/discriminator";

import { builtInPropertiesKeys } from "./collections";
import { getQdrantClient } from "../qdrant";
import { executeQueryById } from "./query";

export async function executeMutation(
mutation: MutationRequest,
config: Config
): Promise<MutationResponse> {
const response: MutationResponse = {
operation_results: [],
};
const qdrantClient = getQdrantClient(config);

for (const operation of mutation.operations) {

switch (operation.type) {
case "insert":
// construct list of points
let points: any = [];
for (const row of operation.rows) {
points.push({
id: Number(row.id),
vector: JSON.parse(row.vector as string),
payload: JSON.parse(row.payload as string),
Comment on lines +32 to +33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing row.vector and row.payload without error handling.

Directly parsing row.vector and row.payload as strings without checking if they are valid JSON strings can lead to runtime errors. Consider adding error handling or validation to ensure these strings are valid JSON before parsing.

});
Comment on lines +28 to +34

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using any type for points array.

Consider defining a more specific type or interface for the points array to improve type safety and code readability.

- let points: any = [];
+ interface Point {
+   id: number;
+   vector: any; // Consider defining a more specific type
+   payload: any; // Consider defining a more specific type
+ }
+ let points: Point[] = [];

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let points: any = [];
for (const row of operation.rows) {
points.push({
id: Number(row.id),
vector: JSON.parse(row.vector as string),
payload: JSON.parse(row.payload as string),
});
interface Point {
id: number;
vector: any; // Consider defining a more specific type
payload: any; // Consider defining a more specific type
}
let points: Point[] = [];
for (const row of operation.rows) {
points.push({
id: Number(row.id),
vector: JSON.parse(row.vector as string),
payload: JSON.parse(row.payload as string),
});

}

await qdrantClient.upsert(operation.table[0], {points: points});
response.operation_results.push({
affected_rows: operation.rows.length,
});
Comment on lines +37 to +40

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No error handling for qdrantClient.upsert call.

The await qdrantClient.upsert(operation.table[0], {points: points}); call lacks error handling. If the upsert operation fails, the error will not be caught, potentially leading to unhandled promise rejections. Consider wrapping this call in a try-catch block and handling errors appropriately.

break;
case "delete":
break;
}
}
return response;
}
3 changes: 1 addition & 2 deletions src/handlers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function executeQueryAll(table: string, query: Query, config: Config) {



async function executeQueryById(
export async function executeQueryById(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removal of expressionQueryType function usage.

The removal of expressionQueryType function usage without removing or refactoring the function definition itself leads to dead code. If the function is no longer needed, consider removing its definition to clean up the codebase.

id: string,
table: string,
query: Query,
Expand Down Expand Up @@ -107,7 +107,6 @@ async function executeQueryById(


function expressionQueryType(query: any){
console.log(query);
switch (query.where.value.value_type) {
case "uuid":
return Number(query.where.value.value);
Expand Down
28 changes: 14 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { getCapabilities } from "./handlers/capabilities";
import { getSchema } from "./handlers/collections";
import { executeQuery } from "./handlers/query";
// import { executeMutation } from "./handlers/mutation";
import { executeMutation } from "./handlers/mutation";

const port = Number(process.env.PORT) || 8200;
const server = Fastify({ logger: { transport: { target: "pino-pretty" } } });
Expand Down Expand Up @@ -65,20 +65,20 @@ server.post<{ Body: QueryRequest; Reply: QueryResponse }>(
}
);

// server.post<{ Body: MutationRequest; Reply: MutationResponse }>(
// "/mutation",
// async (request, _response) => {
// server.log.info(
// { headers: request.headers, query: request.body },
// "mutation.request"
// );
server.post<{ Body: MutationRequest; Reply: MutationResponse }>(
"/mutation",
async (request, _response) => {
server.log.info(
{ headers: request.headers, query: request.body },
"mutation.request"
);

// const config = getConfig(request);
// const mutation = request.body;
// const response = await executeMutation(mutation, config);
// return response;
// }
// );
const config = getConfig(request);
const mutation = request.body;
const response = await executeMutation(mutation, config);
return response;
}
);

server.get("/health", async (request, response) => {
server.log.info(
Expand Down