Skip to content

Order of fields on a type matter for @authorization validation #4054

Open
@afreakk

Description

@afreakk

Describe the bug
In certain scenarios, the order of fields on a type matter for @authorization validation.

To Reproduce

  1. Clone the following repo https://github.com/afreakk/n4j-issue

  2. yarn install

  3. ./test.sh watch-test

  4. Test should now fail with:

    ...snipped...
    -               "id": Any<String>,
    +           "extensions": Object {
    +             "code": "INTERNAL_SERVER_ERROR",
    +             "stacktrace": Array [
    +               "Neo4jGraphQLForbiddenError: Forbidden",
    ...snipped...
    
  5. Now if you change the following type in schema.graphql:

    type VehicleCard
        @authorization(
            validate: [{ where: { node: { tenant: { admins: { userId: "$jwt.id" } } } } }]
        ) {
        id: ID! @id
        garages: [Garage!]! @relationship(type: "VALID_GARAGES", direction: OUT)
        tenant: Tenant! @relationship(type: "VEHICLECARD_OWNER", direction: OUT) # <---  this line
    }
    

    By moving the pointed to line up so the type will look like this:

    type VehicleCard
        @authorization(
            validate: [{ where: { node: { tenant: { admins: { userId: "$jwt.id" } } } } }]
        ) {
        id: ID! @id
        tenant: Tenant! @relationship(type: "VEHICLECARD_OWNER", direction: OUT) # <---  this line
        garages: [Garage!]! @relationship(type: "VALID_GARAGES", direction: OUT)
    }
    
  6. Tests will now pass...
    (you can force save index.test.js to force rerun of tests)

Expected behavior
Order of fields should not have an impact on @authorization.

System (please complete the following information):

  • OS: NixOs
  • Version: @neo4j/graphql@4.2.0
  • Node.js version: v18.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingconfirmedConfirmed bug

    Type

    No type

    Projects

    Status

    Low priority

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions