當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript GraphQLSchema.getDirectives方法代碼示例

本文整理匯總了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;
  }
開發者ID:apollostack,項目名稱:graphql-tools,代碼行數:53,代碼來源:schemaVisitor.ts


注:本文中的graphql.GraphQLSchema.getDirectives方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。