surrealdb / surrealdb.js

SurrealDB SDK for JavaScript
https://surrealdb.com
Apache License 2.0
271 stars 46 forks source link

Bug: Record links inside results of select() not serialized properly? #281

Closed lylejohnson closed 3 weeks ago

lylejohnson commented 3 weeks ago

Describe the bug

The response I get from a call to select does not properly serialize embedded record links (record IDs). As a result, the resulting record ID strings are unusuable in subsequent calls to select.

Steps to reproduce

Here's the query in Surrealist:

SELECT attributes[0] FROM entity:⟨0079835f-100d-43b0-841f-82e273b85abf⟩

and its result, as displayed in Surrealist:

[
    {
        attributes: {
            entitySchemaAttributeId: entity_schema_attribute:⟨374767882363491847329045203645024659⟩,
            id: '304589270060571',
            value: 'thesis atque theca'
        }
    }
]

Note that here, the entitySchemaAttributeId field's value is correctly rendered as a record ID.

However, when I use select in my application to query for the same record:

async getEntity(entityId: string): Promise<SurrealEntity> {
    const response = await this.select<SurrealEntity>(new StringRecordId(entityId));
    console.log(`getEntity: response.attributes[0]: ${response.attributes[0].entitySchemaAttributeId}`);
    return response;
}

It's removing those special bracket characters:

getEntity: response.attributes[0]: entity_schema_attribute:374767882363491847329045203645024659,

This is a change in behavior from 0.11.1.

Expected behaviour

I'd expect the serialization from select for embedded record links like these to be like it was before (or, that there's a documented way to get them to that format?)

SurrealDB version

1.5.0 for linux on x86_64

SurrealDB.js version

1.0.0-beta.9

Contact Details

lyle@lylejohnson.name

Is there an existing issue for this?

Code of Conduct

kearfy commented 3 weeks ago

Good spot! Thanks. I'll get that sorted