-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add initial support for directives
Namely FederationKey for resolveReference decorator
- Loading branch information
Showing
16 changed files
with
512 additions
and
164 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Empty file.
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,3 @@ | ||
|
||
|
||
### Parent |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,66 @@ | ||
import { | ||
GraphQLDirective, | ||
GraphQLSkipDirective, | ||
GraphQLIncludeDirective, | ||
} from 'graphql'; | ||
import { | ||
GraphQLDeferDirective, | ||
GraphQLStreamDirective, | ||
} from '@graphql-tools/utils'; | ||
isSameType, | ||
metaAnnotation, | ||
ReflectionKind, | ||
Type, | ||
TypeAnnotation, | ||
TypeLiteral, | ||
TypeObjectLiteral, | ||
typeOf, | ||
} from '@deepkit/type'; | ||
// import { | ||
// GraphQLDirective, | ||
// GraphQLSkipDirective, | ||
// GraphQLIncludeDirective, | ||
// } from 'graphql'; | ||
// import { | ||
// GraphQLDeferDirective, | ||
// GraphQLStreamDirective, | ||
// } from '@graphql-tools/utils'; | ||
|
||
export const DIRECTIVE_META_NAME = 'directive'; | ||
|
||
export type Directive< | ||
D extends GraphQLDirective | string, | ||
A extends any[] = [], | ||
> = { __meta?: [typeof DIRECTIVE_META_NAME, D, A] }; | ||
export const FEDERATION_KEY_DIRECTIVE_NAME = 'key'; | ||
|
||
export type Defer = Directive<typeof GraphQLDeferDirective>; | ||
// export type Directive< | ||
// D extends GraphQLDirective | string, | ||
// A extends any[] = [], | ||
// > = { __meta?: [typeof DIRECTIVE_META_NAME, D, A] }; | ||
// | ||
// export type Defer = Directive<typeof GraphQLDeferDirective>; | ||
// | ||
// export type Stream = Directive<typeof GraphQLStreamDirective>; | ||
// | ||
// export type Skip = Directive<typeof GraphQLSkipDirective>; | ||
// | ||
// export type Include = Directive<typeof GraphQLIncludeDirective>; | ||
|
||
export type Stream = Directive<typeof GraphQLStreamDirective>; | ||
// TODO: use jsdoc @deprecated instead | ||
// export type Deprecated = Directive<'deprecated', { reason: string }>; | ||
|
||
export type Skip = Directive<typeof GraphQLSkipDirective>; | ||
export interface FieldDirectiveOptions<Name extends string> { | ||
readonly name: Name; | ||
} | ||
|
||
export type Include = Directive<typeof GraphQLIncludeDirective>; | ||
export type FieldDirective<Name extends string> = TypeAnnotation< | ||
typeof DIRECTIVE_META_NAME, | ||
FieldDirectiveOptions<Name> | ||
>; | ||
|
||
// TODO: use jsdoc @deprecated instead | ||
// export type Deprecated = Directive<'deprecated', { reason: string }>; | ||
export type FederationKey = FieldDirective< | ||
typeof FEDERATION_KEY_DIRECTIVE_NAME | ||
>; | ||
|
||
export function getMetaAnnotationDirectives(type: Type): Type[] | undefined { | ||
return metaAnnotation.getForName(type, DIRECTIVE_META_NAME); | ||
} | ||
|
||
export function hasMetaAnnotationDirective( | ||
annotations: readonly Type[], | ||
name: string, | ||
): boolean { | ||
return annotations.some( | ||
annotation => | ||
(annotation.typeArguments![0] as TypeLiteral).literal === name, | ||
); | ||
} |
Oops, something went wrong.