Skip to content

Commit

Permalink
feat(types): enforce typings for rule definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
lvauvillier committed Jul 5, 2020
1 parent df946b5 commit 486ee97
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { IRules } from 'graphql-shield'
import { IOptionsConstructor } from 'graphql-shield/dist/types'
import { IOptionsConstructor, ShieldRule } from 'graphql-shield/dist/types'
import { GetGen } from '@nexus/schema/dist/core'

type GenTypes = Extract<keyof GetGen<'fieldTypes'>, string>
type GenFields<T extends GenTypes> = Extract<
keyof GetGen<'fieldTypes'>[T],
string
>

export type IRuleTypeMap = {
[T in GenTypes]?: ShieldRule | IRuleFieldMap<T>
}
export type IRuleFieldMap<T extends GenTypes> = {
[F in GenFields<T>]?: ShieldRule
} & {
'*'?: ShieldRule
}
export declare type IRules = ShieldRule | IRuleTypeMap

export interface Settings {
rules: IRules
Expand Down

0 comments on commit 486ee97

Please sign in to comment.