aspen-cloud/triplit

Server rejects `triplit.subscribe(triplit.query())` even though the collection exists.

jkoop opened this issue · 2 comments

According to the error messages and logs, the client sends the collection name, but the server rewrites it to be undefined, and then fails the request because the given collection name (undefined) must be string and there isn't a collection called undefined.

I checked for all package updates before reporting this.

schema.ts.gz

// in the script of my Vue3 component
triplit.subscribe(triplit.query('budgets'))
// websocket traffic
➡ {"type":"CONNECT_QUERY","payload":{"id":"14053643006460579916","params":{"id":"6593737870776515","query":{"collectionName":"budgets"}}}}
⬅ {"type":"TRIPLES_REQUEST","payload":{}}
⬅ {"type":"ERROR","payload":{"messageType":"CONNECT_QUERY","error":{"name":"QuerySyncError","message":"An error occurred while syncing your query: {\"id\":\"6593737870776515\",\"query\":{\"collectionName\":\"budgets\"}}","status":500},"metadata":{"queryKey":"14053643006460579916","innerError":{"name":"InvalidCollectionNameError","message":"undefined is not a valid collection name.","status":400,"contextMessage":"Collection name must be a string"}}}}
➡ {"type":"DISCONNECT_QUERY","payload":{"id":"14053643006460579916"}}
> bun triplit dev # npx didn't work either


Triplit Development Environment

You can access your local Triplit services at the following local URLs:

🟢 Console
https://console.triplit.dev/local

🟢 Database
http://localhost:6543

Service Token
[...]

Anonymous Token
[...]

Logs 
Found 0 backwards incompatible schema changes.
Schema update successful
ℹ ⬅ TRIPLES_REQUEST                                                                                                                             2:55:10 p.m.
ℹ ➡ CONNECT_QUERY                                                                                                                               2:55:10 p.m.
InvalidCollectionNameError: undefined is not a valid collection name. | Context: Collection name must be a string
    at validateCollectionName (file:///[...]/my-app/node_modules/@triplit/cli/dist/chunk-XQZRMM24.js:11955:11)
    at prepareQuery (file:///[...]/my-app/node_modules/@triplit/cli/dist/chunk-XQZRMM24.js:11907:3)
    at startSubscription (file:///[...]/my-app/node_modules/@triplit/cli/dist/chunk-XQZRMM24.js:16689:31) {
  status: 400,
  baseMessage: 'undefined is not a valid collection name.',
  contextMessage: 'Collection name must be a string',
  __isTriplitError: true
}
ℹ ⬅ ERROR                                                                                                                                       2:55:10 p.m.
ℹ ➡ DISCONNECT_QUERY                                                                                                                            2:55:10 p.m.

Hey I think this might be a simple fix. I think you just need to call .build() on your query so your code should look more like this:

triplit.subscribe(triplit.query('budgets').build())

This trips a lot of people up so it's something we'll simplify in the future.

Oh that fixed it, thanks. Feel free to close this issue.