-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Enable the use of Permissions of GraphQL field resolvers
Relates to #730
- Loading branch information
1 parent
d3fa83a
commit 5c837b8
Showing
7 changed files
with
189 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/core/e2e/fixtures/test-plugins/with-protected-field-resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ResolveField, Resolver } from '@nestjs/graphql'; | ||
import { Allow, PermissionDefinition, VendurePlugin } from '@vendure/core'; | ||
import gql from 'graphql-tag'; | ||
|
||
export const transactions = new PermissionDefinition({ | ||
name: 'Transactions', | ||
description: 'Allows reading of transaction data', | ||
}); | ||
|
||
@Resolver('Product') | ||
export class ProductEntityResolver { | ||
@Allow(transactions.Permission) | ||
@ResolveField() | ||
transactions() { | ||
return [ | ||
{ id: 1, amount: 100, description: 'credit' }, | ||
{ id: 2, amount: -50, description: 'debit' }, | ||
]; | ||
} | ||
} | ||
|
||
@VendurePlugin({ | ||
adminApiExtensions: { | ||
resolvers: [ProductEntityResolver], | ||
schema: gql` | ||
extend type Query { | ||
transactions: [Transaction!]! | ||
} | ||
extend type Product { | ||
transactions: [Transaction!]! | ||
} | ||
type Transaction implements Node { | ||
id: ID! | ||
amount: Int! | ||
description: String! | ||
} | ||
`, | ||
}, | ||
configuration: config => { | ||
config.authOptions.customPermissions.push(transactions); | ||
return config; | ||
}, | ||
}) | ||
export class ProtectedFieldsPlugin {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters