本文整理匯總了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;
}