Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationship predicates not working on Commands but working for Models #10606

Open
TristenHarr opened this issue Nov 19, 2024 · 0 comments
Open
Labels
k/v3-bug Bug affecting Hasura v3 (DDN)

Comments

@TristenHarr
Copy link
Collaborator

When using a predicate filter that has a relationship, the engine metadata fails to build.

For example, this works properly for models:

---
kind: Model
version: v1
definition:
  name: ProgramStaffs
  objectType: ProgramStaffs
  source:
    dataConnectorName: blendx_pg
    collection: program_staffs
  filterExpressionType: ProgramStaffsBoolExp
  orderableFields:
    - fieldName: id
      orderByDirections:
        enableAll: true
    - fieldName: programId
      orderByDirections:
        enableAll: true
    - fieldName: role
      orderByDirections:
        enableAll: true
    - fieldName: userId
      orderByDirections:
        enableAll: true
  graphql:
    selectMany:
      queryRootField: programStaffs
    selectUniques:
      - queryRootField: programStaffsById
        uniqueIdentifier:
          - id
      - queryRootField: programStaffsByProgramStaffsUserIdProgramIdRoleKey
        uniqueIdentifier:
          - programId
          - role
          - userId
    orderByExpressionType: ProgramStaffsOrderBy
    filterInputTypeName: ProgramStaffsFilterInput
    aggregate:
      queryRootField: programStaffsAggregate
  description: This table keeps track of the staffs of programs
  aggregateExpression: ProgramStaffsAggExp

---
kind: ModelPermissions
version: v1
definition:
  modelName: ProgramStaffs
  permissions:
    - role: admin
      select:
        filter: null
    - role: staff
      select:
        filter:
          and:
            - fieldComparison:
                field: userId
                operator: _eq
                value:
                  sessionVariable: x-hasura-user-id
            - relationship:
                name: program
                predicate:
                  fieldComparison:
                    field: organisationId
                    operator: _eq
                    value:
                      sessionVariable: x-hasura-org-id

However, if you need to do something similar to commands it does not work:

---
kind: Command
version: v1
definition:
  name: V2DeleteProgramStaffsById
  outputType: V2DeleteProgramStaffsByIdResponse!
  arguments:
    - name: keyId
      type: Uuid!
    - name: preCheck
      type: ProgramStaffsBoolExp!
      description: Delete permission predicate over the 'program_staffs' collection
  source:
    dataConnectorName: blendx_pg
    dataConnectorCommand:
      procedure: v2_delete_program_staffs_by_id
    argumentMapping:
      keyId: key_id
      preCheck: pre_check
  graphql:
    rootFieldName: v2DeleteProgramStaffsById
    rootFieldKind: Mutation
  description: Delete any row on the 'program_staffs' collection using the 'id' key

---
kind: CommandPermissions
version: v1
definition:
  commandName: V2DeleteProgramStaffsById
  permissions:
    - role: admin
      allowExecution: true
    - role: super_admin
      allowExecution: true
      argumentPresets:
        - argument: preCheck
          value: 
            booleanExpression: 
              and:
                - fieldComparison:
                    field: userId
                    operator: _eq
                    value: 
                      sessionVariable: x-hasura-user-id
    - role: staff
      allowExecution: true
      argumentPresets:
        - argument: preCheck
          value: 
            booleanExpression: 
              and:
                - fieldComparison:
                    field: userId
                    operator: _eq
                    value: 
                      sessionVariable: x-hasura-user-id
                - relationship:
                    name: program
                    predicate: 
                      fieldComparison:
                        field: organisationId
                        operator: _eq
                        value: 
                          sessionVariable: x-hasura-org-id

Specifically, the relationship check in the boolean expression causes the metadata to fail to build. ddn context set-current-context dev
6:23PM INF Current context set to "dev".
6:23PM INF Checking for update...
HINT A new version (v2.14.0) is available for the DDN CLI, to update run: ddn update-cli
ddn supergraph build local --output-dir engine/build/dev
6:23PM INF Using Supergraph config file "supergraph.dev.yaml" found in context.
6:23PM INF Using localEnvFile ".env.dev" found in context.
6:23PM ERR Code=opendds-validation Message="invalid metadata: error building schema: invalid metadata: Internal Error: Unknown type ProgramStaffsBoolExp (in subgraph app) when collecting type mappings in type ProgramStaffsBoolExp (in subgraph app)"
6:23PM ERR Building Supergraph failed.
make: *** [Makefile:21: ddn-engine-local] Error 1

@TristenHarr TristenHarr added the k/v3-bug Bug affecting Hasura v3 (DDN) label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
k/v3-bug Bug affecting Hasura v3 (DDN)
Projects
None yet
Development

No branches or pull requests

1 participant