-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
rules.ts
27 lines (20 loc) · 800 Bytes
/
rules.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { rule, and, or, not } from 'graphql-shield'
import { Context, getUserEmail } from '../utils'
// Uncomment the comments below to see the number of executions of each rule.
// Magic, right!
// To see the effect with no cache, set { cache: false } in isCustomer rule.
export const isGrocer = rule({ cache: 'contextual' })(
async (parent, args, ctx: Context, info) => {
// console.log('SHIELD: IsGrocer?')
const email = getUserEmail(ctx)
return ctx.db.exists.Grocer({ email })
},
)
export const isCustomer = rule({ cache: 'contextual' })(
async (parent, args, ctx: Context, info) => {
// console.log('SHIELD: IsCustomer?')
const email = getUserEmail(ctx)
return ctx.db.exists.Customer({ email })
},
)
export const isAuthenticated = or(isCustomer, isGrocer)