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

withAuth and authScopes don't combine #1192

Open
GauBen opened this issue Apr 18, 2024 · 2 comments
Open

withAuth and authScopes don't combine #1192

GauBen opened this issue Apr 18, 2024 · 2 comments

Comments

@GauBen
Copy link
Contributor

GauBen commented Apr 18, 2024

Hey, I noticed that while you can use both withAuth and authScopes on the same field, it does not actually combine declarations despite what type declarations lead to think

https://github.com/hayes/pothos/blob/3cebfed6f033ee92c2b3492a3fd6d3002906ab08/packages/plugin-scope-auth/src/field-builders.ts#L58C7-L58C26

Example:

builder.mutationField('updateUserPropery', (t) =>
  t.withAuth({ user: true }).boolean({
    authScopes(_, args, context) {
      // Here `context` will be typed according to `AuthContexts`
      // but `{ user: true }` will be overwritten by this function
    },
    resolve() {
      // ...
    }
  })
)

Instead, I'd like both { user: true } and authScopes(){} to be merged

@hayes
Copy link
Owner

hayes commented Apr 19, 2024

That seems reasonable to me, I think modifying this line

To do something like this would work

authScopes: options.authScopes ? { $all: [scopes, options.authScopes] } : scopes,

@hayes
Copy link
Owner

hayes commented Apr 19, 2024

It's probably a little more complex, i think my example works if the new scopes are an object, but not if it's a function. Handling the function case should be pretty easy though by wrapping it to return the merged scopes

@GauBen GauBen changed the title withAuth and authScopes don't dombine withAuth and authScopes don't combine Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants