@8base-js-sdk/api tranformResponse Error

Hello, I’m currently attempting to make use of the @8base-js-sdk/api package (v0.1.6) from npm and am experiencing an error when using the transformResponse property in the config.

I’m able to query and mutate with this lib perfectly fine without this property enabled, but I was hoping to be able to use it as it is part of the package and should work.

Below is the lib in its entirety as well as the error I’m receiving. Any help with this problem is appreciated.

import EightBaseApi from '@8base-js-sdk/api'
import { parseCookies } from 'nookies'

export const config = {
    workspaceId: process.env.NEXT_PUBLIC_8BASE_ENVIRONMENT,
    timeout: 1000,
    headers: {
        Authorization: `Bearer ${parseCookies().idToken}`
    },
    // API calls can be transformed before a request is sent using one or more transformation functions.
    // All functions will execute in order and updated values get passed to the following function.
    // Example of this concept below:
    // transformRequest: [
    //     (next, data) => {
    //         next({
    //             ...data,
    //             variables: {
    //                 data: {
    //                     timestamp: fixedTimestamp
    //                 }
    //             }
    //         })
    //     },
    //     (next, data) => {
    //         next({
    //             ...data
    //             // Something else!
    //         })
    //     }
    // ]
    // Successful API responses can be transformed before the promise is resolved.
    // All functions will execute in order and updated values get passed to the following function.
    // Example of this concept below:
    transformResponse: [
        (next, data) => {
            next({
                ...data,
                response: {
                    data: {
                        test: '123'
                    }
                }
            })
        }
    ]
    // Failed API requests can be captured when a response is recieved.
    // Example of this concept below:
    // catchErrors: {
    //     TokenExpiredError: (err, reRun) => {},
    //     default: (err, reRun) => {}
    // }
}

export default new EightBaseApi(config)

Weird… can you try renaming your “response” key name? I’m wondering if an underlying library is expecting a key with the name “response” to be there.

@sebastian.scholl Hey Sebastian, thanks for the reply. Renaming that response key doesn’t have any effect - the error persists even after doing so. I’ve also tried it without including that response object in general, but still receive the same error.

The function I have in my uploaded code snippet is practically identical to the one that’s used in the documentation’s example Api Module - 8base Documentation, so I would have assumed the example code was functional but it doesn’t appear to be.

I’ve also logged data and it does in fact exist so the function is definitely receiving the promised data from 8base but seems to just fail when this next function invokes. Even doing something as small as the below code will result in the same error.

transformResponse: [
        (next, data) => {
            next({
                test: '123'
            })
        }
    ]

Is this possibly a bug in the sdk? Also, just for my knowledge, this sdk has a version number of 0.1.6, is this sdk still in beta?

Yeah, it seems like a bug. Creating a support ticket for this. Maybe try using a different version? Otherwise, I’d recommend using a different GraphQL API client until we make ours stronger.