-
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.
Merge pull request #22 from thuoe/next
Release `next`: 2024/03/18
- Loading branch information
Showing
5 changed files
with
31 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { DirectableGraphQLObject, getDirective } from '@graphql-tools/utils' | ||
import { GraphQLSchema } from 'graphql' | ||
|
||
export const isValidDirective = <T extends Record<string, unknown>>(directive: unknown): directive is T => { | ||
return typeof directive === 'object' && directive !== null | ||
} | ||
|
||
export const fetchDirective = <T extends Record<string, unknown>>(schema: GraphQLSchema, fieldConfig: DirectableGraphQLObject, directiveName: string): T => { | ||
const directive = getDirective(schema, fieldConfig, directiveName)?.[0] | ||
const isValid = isValidDirective<T>(directive) | ||
if (isValid) { | ||
return directive | ||
} | ||
return null | ||
} |