-
-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mapSchema can support copying graphql object annotations, but annotations will have to be copied for every graphql object whenever a new schema, type, enumValue, field, argument, is created. this change just covers type annotations with symbols and property annotations for object types
- Loading branch information
Showing
5 changed files
with
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { GraphQLNamedType, isObjectType } from 'graphql'; | ||
|
||
export function annotateType<T extends GraphQLNamedType>(newType: T, originalType: T): T { | ||
const symbols = Object.getOwnPropertySymbols(originalType); | ||
symbols.forEach(symbol => { | ||
newType[symbol] = originalType[symbol]; | ||
}); | ||
|
||
if (isObjectType(newType)) { | ||
const names = Object.getOwnPropertyNames(originalType); | ||
const objectPropertyNames = ['name', 'description', 'isTypeOf', 'extensions', 'astNode', 'extensionASTNodes']; | ||
names.forEach(name => { | ||
if (!objectPropertyNames.includes(name) && !name.startsWith('_')) { | ||
newType[name] = originalType[name]; | ||
} | ||
}); | ||
} | ||
return newType; | ||
} |
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