Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] TypeScript API Bugs and Proposed Solutions #1131

Closed
pinghe opened this issue Jun 19, 2024 · 3 comments · Fixed by #1140
Closed

[api] TypeScript API Bugs and Proposed Solutions #1131

pinghe opened this issue Jun 19, 2024 · 3 comments · Fixed by #1140
Assignees
Labels

Comments

@pinghe
Copy link
Contributor

pinghe commented Jun 19, 2024

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
Copy link
Collaborator

Thanks for reporting this, I will get it fixed.

@michaelvlach michaelvlach self-assigned this Jun 19, 2024
@michaelvlach michaelvlach moved this to Todo in agdb Jun 19, 2024
@michaelvlach michaelvlach moved this from Todo to In Progress in agdb Jul 8, 2024
@michaelvlach michaelvlach linked a pull request Jul 14, 2024 that will close this issue
michaelvlach added a commit that referenced this issue Jul 14, 2024
* test queries

* generate tests & fixes

* cleanup tests

* fix conversions

* fixing coverage

* fixing coverage

* finalize coverage

* fix example

* update docs

* fix typo

* fix typo

* update deps

* fixes

* fix lint pattern
@github-project-automation github-project-automation bot moved this from In Progress to Done in agdb Jul 14, 2024
@agnesoft
Copy link
Owner

@pinghe This is now fixed. I have dramatically improved the ergonomics of the TS API. For example there are many wrappers now that lets you use the native TS types without the need to specify the full JSON represenation (still possible though). Similarly many functions that required array now can accept single param as well that will be internally made into an array.

Lastly and most importantly I have made it so that client is no longer global and can be instantiated as many times as needed with possibly different hosts / logins. I have also added login() shorthand to avoid login+setting tokent (still possible though).

As part of this I have also significantly revamped and improved on the API testing but please let me know if you encounter any issues!

@pinghe
Copy link
Contributor Author

pinghe commented Jul 27, 2024

@agnesoft Thank you. I will update to the latest version and verify it in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants