-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
165 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export const usageSymbol = Symbol.for('Pothos.isUsed'); | ||
|
||
export function wrapWithUsageCheck<T extends Object>(obj: T): T { | ||
const result = {}; | ||
let used = true; | ||
|
||
Object.defineProperty(result, usageSymbol, { | ||
get() { | ||
return used; | ||
}, | ||
enumerable: false, | ||
}); | ||
|
||
for (const key of Object.keys(obj)) { | ||
// only set to false if the object has keys | ||
used = false; | ||
Object.defineProperty(result, key, { | ||
enumerable: true, | ||
configurable: true, | ||
// eslint-disable-next-line @typescript-eslint/no-loop-func | ||
get() { | ||
used = true; | ||
return obj[key as keyof T]; | ||
}, | ||
}); | ||
} | ||
|
||
return result as T; | ||
} | ||
|
||
export function isUsed(obj: object): boolean { | ||
return !(usageSymbol in obj) || (obj as { [usageSymbol]: boolean })[usageSymbol]; | ||
} |
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
21e4014
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
pothos – ./
pothos.vercel.app
pothos-mhayes.vercel.app
pothos-graphql.dev
pothos-git-main-mhayes.vercel.app
www.pothos-graphql.dev