TriPSs / nestjs-query

Easy CRUD for GraphQL.
https://tripss.github.io/nestjs-query/
MIT License
164 stars 46 forks source link

Allow using auth filters on creation #321

Open Smtih opened 4 days ago

Smtih commented 4 days ago

Following up on conversation here: https://github.com/TriPSs/nestjs-query/issues/320

When getting started with nestjs-query I found it un-intuitive that my authorizers would be executed during the creation flow, but then not evaluated in any way to prevent creation of resources that didn't match my auth criteria.

This PR allows users to opt in to having their authorization filters used when hitting creation end points.

Open Questions:

@TriPSs I'll start on test coverage once we're happy with the overall direction.

TriPSs commented 4 days ago

Just now saw the open questions, sorry.

Open Questions:

Where should the opt-in configuration be done? -- My feeling is in the resolver options

Would indeed say the resolver options (better naming is welcome):

{
  resolvers: [{
    create: {
      one: { validateWithAuthFilter: true },
      many: { validateWithAuthFilter: true },

      validateWithAuthFilter: true // Enable for both
    }
  }]
}

Where should the access be evaluated? -- The original implementation I had done implemented this in the typeorm-query-service however, given that we are evaluating the filters in JS we could move it to the resolver. My issue with that is I don't think this works very well with the assembler paradigm if you're CreateDTO is significantly different from core DTO/entity

Agree, where it is now is indeed the best.

nx-cloud[bot] commented 3 days ago

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 07f3ae9550a7b259b822c8e0f2be86456399ef99. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx run-many --target=test --all
nx run-many --target=lint --all
✅ Successfully ran 3 targets - [`nx run-many --target=e2e --all`](https://cloud.nx.app/runs/METkSn1156?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=build --all`](https://cloud.nx.app/runs/IT5s4B3gDF?utm_source=pull-request&utm_medium=comment) - [`nx run workspace:version`](https://cloud.nx.app/runs/X1Lmo0gqYh?utm_source=pull-request&utm_medium=comment)

Sent with 💌 from NxCloud.