@graphql-mesh/transport-rest
Version:
30 lines (29 loc) • 1.07 kB
JavaScript
import { valueFromASTUntyped } from 'graphql';
export function getDirectiveAnnotations(directableObj) {
const directiveAnnotations = [];
const directiveExtensions = directableObj.extensions?.directives;
if (directiveExtensions) {
for (const directiveName in directiveExtensions) {
const args = directiveExtensions[directiveName];
directiveAnnotations.push({
name: directiveName,
args,
});
}
}
const directiveAstNodes = directableObj.astNode?.directives;
if (directiveAstNodes) {
for (const directiveNode of directiveAstNodes) {
const args = {};
for (const argNode of directiveNode.arguments || []) {
const argValue = valueFromASTUntyped(argNode.value);
args[argNode.name.value] = argValue;
directiveAnnotations.push({
name: directiveNode.name.value,
args,
});
}
}
}
return directiveAnnotations;
}