agnesoft / agdb

Agnesoft Graph Database
Apache License 2.0
51 stars 2 forks source link

[api] TypeScript API Bugs and Proposed Solutions #1131

Open pinghe opened 1 week ago

pinghe commented 1 week ago

I've identified a few bugs in our TypeScript API implementation that need to be addressed. Below are the issues and my proposed solutions for each:

Bug 1: Axios baseURL Not Set

Issue: The axios instance is not configured with a baseURL, which causes issues when a custom prefix is set and needs to take effect. Proposed Solution: In client.ts, set the baseURL for the axios configuration as follows:

AgdbApi.api = new OpenAPIClientAxios({
    definition: `${address}/api/v1/openapi.json`,
    axiosConfigDefaults: {
        baseURL: `${address}`, // Set axios's baseURL
    },
});

Bug 2: InsertNodesBuilder Not Passing IDs

Issue: The InsertNodesBuilder is not passing ids, which results in them not being effective.

Proposed Solution: In query_builder.ts, modify the ids method to ensure ids are passed correctly:

ids(
    ids:
        | QueryId[]
        | Components.Schemas.QueryType
        | Components.Schemas.QueryResult,
) {
    this.data.ids = intoQueryIds(ids);
    return new InsertNodesIdsBuilder(this.data);
}

And update the InsertNodesIdsBuilder class constructor to handle undefined data properly:

class InsertNodesIdsBuilder {
    private data: Components.Schemas.InsertNodesQuery;

    constructor(data: Components.Schemas.InsertNodesQuery | undefined) {
        if (data) {
            this.data = data;
        } else {
            this.data = {
                count: 0,
                aliases: [],
                ids: { Ids: [] },
                values: {
                    Single: [],
                },
            };
        }
    }
}

Bug 3: InsertEdgesBuilder Has Similar Issue as Bug 2

Issue: The InsertEdgesBuilder faces the same problem as InsertNodesBuilder where ids are not being passed effectively.

Proposed Solution: In query_builder.ts, adjust the ids method for InsertEdgesBuilder similar to the solution for InsertNodesBuilder:

ids(
    ids:
        | QueryId[]
        | Components.Schemas.QueryType
        | Components.Schemas.QueryResult,
) {
    this.data.ids = intoQueryIds(ids);
    return new InsertEdgesIdsBuilder(this.data);
}

Ensure the InsertEdgesIdsBuilder class is correctly handling the query data:

class InsertEdgesIdsBuilder {
    private data: Components.Schemas.InsertEdgesQuery;

    constructor(query: Components.Schemas.InsertEdgesQuery) {
        this.data = query;
    }
}

I believe these solutions will resolve the current bugs and improve the stability and functionality of our API.

Thank you for your review and consideration.

Best regards, pinghe

michaelvlach commented 1 week ago

Thanks for reporting this, I will get it fixed.