From 486ee970cd81a46a93f6ec8f59e888678bc2b1fb Mon Sep 17 00:00:00 2001 From: Luc Vauvillier Date: Sun, 5 Jul 2020 18:17:38 +0200 Subject: [PATCH] feat(types): enforce typings for rule definitions --- src/settings.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/settings.ts b/src/settings.ts index e7e3ef8..2a51a18 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -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, string> +type GenFields = Extract< + keyof GetGen<'fieldTypes'>[T], + string +> + +export type IRuleTypeMap = { + [T in GenTypes]?: ShieldRule | IRuleFieldMap +} +export type IRuleFieldMap = { + [F in GenFields]?: ShieldRule +} & { + '*'?: ShieldRule +} +export declare type IRules = ShieldRule | IRuleTypeMap export interface Settings { rules: IRules