本文整理汇总了TypeScript中graphql.GraphQLSchema.getDirectives方法的典型用法代码示例。如果您正苦于以下问题:TypeScript GraphQLSchema.getDirectives方法的具体用法?TypeScript GraphQLSchema.getDirectives怎么用?TypeScript GraphQLSchema.getDirectives使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphql.GraphQLSchema
的用法示例。
在下文中一共展示了GraphQLSchema.getDirectives方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getDeclaredDirectives
protected static getDeclaredDirectives(
schema: GraphQLSchema,
directiveVisitors: {
[directiveName: string]: typeof SchemaDirectiveVisitor
},
) {
const declaredDirectives: {
[directiveName: string]: GraphQLDirective,
} = Object.create(null);
each(schema.getDirectives(), (decl: GraphQLDirective) => {
declaredDirectives[decl.name] = decl;
});
// If the visitor subclass overrides getDirectiveDeclaration, and it
// returns a non-null GraphQLDirective, use that instead of any directive
// declared in the schema itself. Reasoning: if a SchemaDirectiveVisitor
// goes to the trouble of implementing getDirectiveDeclaration, it should
// be able to rely on that implementation.
each(directiveVisitors, (visitorClass, directiveName) => {
const decl = visitorClass.getDirectiveDeclaration(directiveName, schema);
if (decl) {
declaredDirectives[directiveName] = decl;
}
});
each(declaredDirectives, (decl, name) => {
if (! hasOwn.call(directiveVisitors, name)) {
// SchemaDirectiveVisitors.visitSchemaDirectives might be called
// multiple times with partial directiveVisitors maps, so it's not
// necessarily an error for directiveVisitors to be missing an
// implementation of a directive that was declared in the schema.
return;
}
const visitorClass = directiveVisitors[name];
each(decl.locations, loc => {
const visitorMethodName = directiveLocationToVisitorMethodName(loc);
if (SchemaVisitor.implementsVisitorMethod(visitorMethodName) &&
! visitorClass.implementsVisitorMethod(visitorMethodName)) {
// While visitor subclasses may implement extra visitor methods,
// it's definitely a mistake if the GraphQLDirective declares itself
// applicable to certain schema locations, and the visitor subclass
// does not implement all the corresponding methods.
throw new Error(
`SchemaDirectiveVisitor for @${name} must implement ${visitorMethodName} method`
);
}
});
});
return declaredDirectives;
}