Skip to content

Data Connect @check in query doesn't work - should it? #8133

@zmullett

Description

@zmullett

[REQUIRED] Environment info

firebase-tools: 13.29.1

Platform: macOS

[REQUIRED] Test case

Attempting to check for membership by row presence in OrganizationMembership when querying for an Organization row by ID.

schema.gql:

type Organization @table {
  id: UUID! @default(expr: "uuidV4()")
  title: String!
}

type OrganizationMembership @table(key: ["organization", "uid"]) {
  organization: Organization!
  uid: String!
}

queries.gql:

query GetOrganizationById($organizationId: UUID!) @auth(level: USER) {
  organization(id: $organizationId) {
    organizationMemberships_on_organization(
      where: { uid: { eq_expr: "auth.uid" } }
    ) @check {
      uid  # dummy field
    }
    title
  }
}

[REQUIRED] Steps to reproduce

  1. Add test Organization and OrganizationMembership rows. The following mutations could be used:
mutation CreateOrganization($title: String!) @auth(level: NO_ACCESS) {
  organization_insert(data: { title: $title })
}

mutation UpsertOrganizationMembership($organizationId: UUID!, $uid: String!)
@auth(level: NO_ACCESS) {
  organizationMembership_upsert(
    data: { organizationId: $organizationId, uid: $uid }
  )
}

[REQUIRED] Expected behavior

Inclusion of the @check directive has the effect of returning an error if the expression evaluates to false, otherwise is a no-op.

[REQUIRED] Actual behavior

W0123 17:08:33.851394   32250 engine.go:152] [engine.Service /emulator/my-project ebb4] ExecuteQuery GetOrganizationById: failed. Connector: default
Auth: user of {...some-firebase-auth-details...}
Variables:
{
   "organizationId": "9ffb14d5-fbd9-4ee9-8cb8-10a37ba153ab"
 }
Errors: input: cannot commit transaction: pq: unexpected transaction status idle

Data:
[...see below...]
sources: connector/mutations.gql [483B] connector/queries.gql [673B] 

The Data array, decoded:

{
   "organization": {
     "organizationMemberships_on_organization": [
       {
         "uid": "some-firebase-auth-uid"
       }
     ],
     "title": "Test Organization"
   }
 }

The emulator is then left in a broken state and needs restarting. Prior to restarting, any schema modifications and subsequent queries result in a such an error: SQL Error: pq: prepared statement "1" already exists

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions