unbody-io / ts-client

Typescript client for Unbody's API
https://unbody.io/docs/libraries/typescript-client
7 stars 1 forks source link

TypeScript Client for Unbody's GraphQL API #1

Closed jeangovil closed 7 months ago

amirhouieh commented 1 year ago

Description:

We require the development of a TypeScript client that interfaces with Unbody's GraphQL API. This client will strictly serve as a read-only interface, meaning no mutations are to be performed. It's important to note that Unbody utilizes Weaviate as its primary database. Consequently, all the operators, filters, and other functionalities will be consistent with those provided by Weaviate.

Objectives:

  1. Create a seamless client that allows developers to easily interact with Unbody's API, focusing on retrieval operations.
  2. Ensure compatibility and functionality mirroring Weaviate's operators and filters.
  3. Prioritize developer experience, promoting intuitive method chaining and clear query structure.

Potential Approaches:

1. Apollo Client Integration:

2. Custom Client Development (Current Proposal):

3. A combination of both?

While leveraging the powerful functionalities such as caching mechanism and local variables provided by Apollo, we can still design our own class base interface like approach 2.

Feedback and Collaboration:

We welcome contributions, ideas, and feedback from the community. If you have expertise or suggestions regarding these approaches or envision another potential solution, please share.

miladazhdehnia commented 1 year ago

Description:

This proposal aims to create a more readable and reusable syntax based on my experience as a full-stack developer. If you're interested, we can discuss these approaches further.

Approaches:

  1. These approaches are more like an ORM/ODM, and we can have both at same time.

I think this more readable in terms of nested where, orWhere and other query operators.

const response = await unbody.gdoc.find({
    where: {
        title: 'Bitcoin' /* default behaviour = equals */,
        orWhere: {
            title: {like: 'Ethereum'}
        }
    },
    nearText: ['cryptocurrency'],
    select: ['title'], /* and { exclude: ['id'] }, this way we can get every field except excluded */
    /* limit, pagination and other options */
})

This is more favorable for chain lovers :D.

const response = await unbody.gdoc
    .find()
    .where({title: 'Bitcoin'})
    .orWhere({title: {like: 'Ethereum'}})
    .nearText(['cryptocurrency'])
    .select(['title'])
    .exec()
  1. This approach should be designed to function like an SDK.
    
    // We can reuse gdoc object
    const gdocListEntity = unbody.gdoc({fields: ['title'] /* and { exclude: ['id'] }, this way we can get every field except excluded */, /* limit, pagination and other options */})

const cryptoDocs = gdocListEntity .title('Bitcoin', 'Tron') .html('

text
') .alternate() // syntax sugar for or operator .title({like: 'Ethereum'})

const fiatDocs = gdocListEntity .title('United states dollar') .html('

USD
') .alternate() // syntax sugar for or operator .title({like: 'USD'}) .get() // Replacement for exec

const gdocSingleEntity = unbody.gdoc({ fields: ['title', 'html'] / and { exclude: ['id'] }, this way we can get every field except excluded /, limit: 1 / limit, pagination and other options /, }) const fiatDocs = gdocSingleEntity .id('XXXXXX') .get() // Replacement for exec

amirhouieh commented 1 year ago

@miladazhdehnia Thanks for the proposal. I see we both see potential in Approach 2, and we think it's the best way forward.

A couple of things I'm wondering about:

Keen to hear your thoughts 🤔

miladazhdehnia commented 1 year ago

As we've decided to move forward with the second proposed approach, the implementation will kick off from here