当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript GraphQLFieldResolver.default方法代码示例

本文整理汇总了TypeScript中graphql.GraphQLFieldResolver.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript GraphQLFieldResolver.default方法的具体用法?TypeScript GraphQLFieldResolver.default怎么用?TypeScript GraphQLFieldResolver.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphql.GraphQLFieldResolver的用法示例。


在下文中一共展示了GraphQLFieldResolver.default方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: return

 return (obj, args, ctx, info) => {
   return Promise.resolve(outerResolver(obj, args, ctx, info)).then(root => {
     if (innerResolver) {
       return innerResolver(root, args, ctx, info);
     }
     return defaultFieldResolver(root, args, ctx, info);
   });
 };
开发者ID:apollostack,项目名称:graphql-tools,代码行数:8,代码来源:addSchemaLevelResolveFunction.ts

示例2: copyOwnProps

        field.resolve = (
          rootObject?: any,
          args?: { [key: string]: any },
          context?: any,
          info?: GraphQLResolveInfo,
        ) =>
          Promise.all([
            mockResolver(rootObject, args, context, info),
            oldResolver(rootObject, args, context, info),
          ]).then(values => {
            const [mockedValue, resolvedValue] = values;

            // In case we couldn't mock
            if (mockedValue instanceof Error) {
              // only if value was not resolved, populate the error.
              if (undefined === resolvedValue) {
                throw mockedValue;
              }
              return resolvedValue;
            }

            if (resolvedValue instanceof Date && mockedValue instanceof Date) {
              return undefined !== resolvedValue ? resolvedValue : mockedValue;
            }

            if (isObject(mockedValue) && isObject(resolvedValue)) {
              // Object.assign() won't do here, as we need to all properties, including
              // the non-enumerable ones and defined using Object.defineProperty
              const emptyObject = Object.create(
                Object.getPrototypeOf(resolvedValue),
              );
              return copyOwnProps(emptyObject, resolvedValue, mockedValue);
            }
            return undefined !== resolvedValue ? resolvedValue : mockedValue;
          });
开发者ID:sventschui,项目名称:graphql-tools,代码行数:35,代码来源:mock.ts

示例3: return

  return (root, args, ctx, info) => {
    try {
      const result = fn(root, args, ctx, info);
      // If the resolve function returns a Promise log any Promise rejects.
      if (
        result &&
        typeof result.then === 'function' &&
        typeof result.catch === 'function'
      ) {
        result.catch((reason: Error | string) => {
          // make sure that it's an error we're logging.
          const error = reason instanceof Error ? reason : new Error(reason);
          logError(error);

          // We don't want to leave an unhandled exception so pass on error.
          return reason;
        });
      }
      return result;
    } catch (e) {
      logError(e);
      // we want to pass on the error, just in case.
      throw e;
    }
  };
开发者ID:apollostack,项目名称:graphql-tools,代码行数:25,代码来源:decorateWithLogger.ts

示例4: Error

 return (root, args, ctx, info) => {
   const result = fn(root, args, ctx, info);
   if (typeof result === 'undefined') {
     throw new Error(`Resolve function for "${hint}" returned undefined`);
   }
   return result;
 };
开发者ID:apollostack,项目名称:graphql-tools,代码行数:7,代码来源:makeExecutableSchema.ts


注:本文中的graphql.GraphQLFieldResolver.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。