firebase / firebase/firebase-tools

Unable to query / mutate a table after adding fields referencing the same type

Open
#8,567 2 comments 1 reaction 0 assignees View on GitHub
emulator: dataconnect type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

As I am working with DataConnect, I am trying to implement a versionning system where given an "Application" , it may have different "Snapshots", where each points to the previous and next version, if those exists respectively.

Initially, I was unable to reference the `Snapshot` table/type and dataconnect would give me the compilation error
```
On Snapshot.previous @ref(references): Reference another reference field Snapshot.applicationFirebase Data Connect: Compiler
```
whenever I tried to do so. And to work around that, I had to manually add a unique `id` field of type `UUID`. Then, reference the specific `id` field each time I want to reference my Snapshot as in `Snapshot @ref(references: "id")`. Using that, the compiler doesn't displays errors anymore, both for my schema and my CRUD operations.

But then, as soon as I try to access the `Application` whether for a query or a mutation, the emulator will crash immediately and give me the error
```Error: Emulator Request failed with status 400
Error Response: {"code":9,"message":"cannot prepare SQL statement:\nSELECT coalesce(json_agg(j), '[]') FROM (SELECT jsonb_build_object('currentId', REPLACE(CAST(( \"current_id\" ) AS text), '-', '')) AS j FROM \"public\".\"application\" LIMIT 100) AS x\nSQL Error: pq: unexpected message 'E'; expected ReadyForQuery","details":[]}
at Yg.handleEmulatorResponse (c:\{...}\extensions\googlecloudtools.firebase-dataconnect-vscode-1.3.1\dist\extension.js:8:5866458)
at Yg.executeGraphQL (c:\{...}\extensions\googlecloudtools.firebase-dataconnect-vscode-1.3.1\dist\extension.js:8:5868703)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at d (c:\{...}\extensions\googlecloudtools.firebase-dataconnect-vscode-1.3.1\dist\extension.js:8:5860714)
```
and I get a similar error if i try to access a `Snapshot`

But I notice that if I comment out my reference fields, everything works fine !

Here is the schema:

```
type Application @table {
current: Snapshot @ref(references: "id")
latest: Snapshot @ref(references: "id")
}

type Snapshot @table (key: [ "application", "version"]) {
# The id property must be there, else, can't self reference
id: UUID! @unique
application: Application!
version: String!
previous: Snapshot @ref(references: "id")
next: Snapshot @ref(references: "id")
}
```

Expected Behaviour: To be able to query and mutate my Applications and Snapshots normally and access linked resources (prev/next, current/latest navigation)
Actual Behaviour: Emulator crashes unexpectedly when any interaction is initiated with the specified types

**Environment**
**firebase-tools**: `14.3.1`
**firebase dataconnect vscode extension**: `1.3.1`
**node**: `v22.14.0` **
**operating system**: `windows`
**terminal**: `powershell`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.