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


TypeScript graphql.responsePathAsArray函数代码示例

本文整理汇总了TypeScript中graphql.responsePathAsArray函数的典型用法代码示例。如果您正苦于以下问题:TypeScript responsePathAsArray函数的具体用法?TypeScript responsePathAsArray怎么用?TypeScript responsePathAsArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: checkResultAndHandleErrors

export function checkResultAndHandleErrors(
  result: ExecutionResult,
  info: GraphQLResolveInfo,
  responseKey?: string
): any {
  if (!responseKey) {
    responseKey = getResponseKeyFromInfo(info);
  }

  if (result.errors && (!result.data || result.data[responseKey] == null)) {
    // apollo-link-http & http-link-dataloader need the
    // result property to be passed through for better error handling.
    // If there is only one error, which contains a result property, pass the error through
    const newError =
      result.errors.length === 1 && hasResult(result.errors[0])
        ? result.errors[0]
        : new CombinedError(concatErrors(result.errors), result.errors);
    throw locatedError(newError, info.fieldNodes, responsePathAsArray(info.path));
  }

  let resultObject = result.data[responseKey];
  if (result.errors) {
    resultObject = annotateWithChildrenErrors(resultObject, result.errors as ReadonlyArray<GraphQLFormattedError>);
  }
  return resultObject;
}
开发者ID:apollostack,项目名称:graphql-tools,代码行数:26,代码来源:errors.ts

示例2: getResponseKeyFromInfo

const defaultMergedResolver: GraphQLFieldResolver<any, any> = (parent, args, context, info) => {
  if (!parent) {
    return null;
  }

  const responseKey = getResponseKeyFromInfo(info);
  const errorResult = getErrorsFromParent(parent, responseKey);

  if (errorResult.kind === 'OWN') {
    throw locatedError(new Error(errorResult.error.message), info.fieldNodes, responsePathAsArray(info.path));
  }

  let result = parent[responseKey];

  if (result == null) {
    result = parent[info.fieldName];
  }

  // subscription result mapping
  if (!result && parent.data && parent.data[responseKey]) {
    result = parent.data[responseKey];
  }

  if (errorResult.errors) {
    result = annotateWithChildrenErrors(result, errorResult.errors);
  }
  return result;
};
开发者ID:apollostack,项目名称:graphql-tools,代码行数:28,代码来源:defaultMergedResolver.ts

示例3: checkResultAndHandleErrors

export function checkResultAndHandleErrors(
  result: any,
  info: GraphQLResolveInfo,
  responseKey?: string,
): any {
  if (!responseKey) {
    responseKey = info.fieldNodes[0].alias
      ? info.fieldNodes[0].alias.value
      : info.fieldName;
  }
  if (result.errors && (!result.data || result.data[responseKey] == null)) {
    const errorMessage = result.errors
      .map((error: { message: string }) => error.message)
      .join('\n');
    throw locatedError(
      errorMessage,
      info.fieldNodes,
      responsePathAsArray(info.path),
    );
  } else {
    let resultObject = result.data[responseKey];
    if (result.errors) {
      resultObject = annotateWithChildrenErrors(
        resultObject,
        result.errors as Array<{ path?: Array<string> }>,
      );
    }
    return resultObject;
  }
}
开发者ID:sventschui,项目名称:graphql-tools,代码行数:30,代码来源:errors.ts

示例4: getErrorsFromParent

const defaultMergedResolver: GraphQLFieldResolver<any, any> = (
  parent,
  args,
  context,
  info,
) => {
  const responseKey = info.fieldNodes[0].alias
    ? info.fieldNodes[0].alias.value
    : info.fieldName;
  const errorResult = getErrorsFromParent(parent, responseKey);
  if (errorResult.kind === 'OWN') {
    throw locatedError(
      errorResult.error.message,
      info.fieldNodes,
      responsePathAsArray(info.path),
    );
  } else if (parent) {
    let result = parent[responseKey];
    if (errorResult.errors) {
      result = annotateWithChildrenErrors(result, errorResult.errors);
    }
    return result;
  } else {
    return null;
  }
};
开发者ID:sventschui,项目名称:graphql-tools,代码行数:26,代码来源:defaultMergedResolver.ts

示例5: error

function error(info: GraphQLResolveInfo, renderMessage: (args: { type: string; path: string }) => string) {
  return new Error(
    renderMessage({
      path: responsePathAsArray(info.path).join("/"),
      type: info.returnType.inspect(),
    })
  )
}
开发者ID:artsy,项目名称:emission,代码行数:8,代码来源:index.ts

示例6: responsePathAsArray

    fieldResolver: ((source, _args, _context, info) => {
      const pathAsArray = responsePathAsArray(info.path)
      if (pathAsArray.length === 1) {
        // source is null for root fields
        source = source || (info.operation.operation === "mutation" ? mockMutationResults : mockData)
      }

      // fail early if source is not an object type
      // this happens because graphql only checks for null when deciding
      // whether to resolve fields in a given value
      if (typeof source !== "object") {
        const parentPath = pathAsArray.slice(0, -1).join("/")
        throw new Error(`The value at path '${parentPath}' should be an object but is a ${typeof source}.`)
      }

      // handle aliased fields first
      const alias = info.fieldNodes[0].alias
      if (alias && alias.value in source) {
        return inferUnionOrInterfaceType(checkLeafType(source[alias.value], info), info)
      }

      // the common case, the field has a fixture and is not aliased
      if (info.fieldName in source) {
        return inferUnionOrInterfaceType(checkLeafType(source[info.fieldName], info), info)
      }

      if (info.fieldName === "__id" || info.fieldName === "id") {
        // if relay is looking for `__id` but we only supplied `id`
        if ("id" in source) {
          return source.id
        }

        // relay is looking for an id to denormalize the fixture in the store
        // but we don't want to have to specify ids for all fixtures
        // so generate one and store it in a weak map so we don't mutate
        // the object itself
        if (idMap.has(source)) {
          return idMap.get(source)
        }

        const id = uuid()
        idMap.set(source, id)
        return id
      }

      throw error(
        info,
        ({ type, path }) => `A mock for field at path '${path}' of type '${type}' was expected but not found.`
      )
    }) as GraphQLFieldResolver<any, any>,
开发者ID:artsy,项目名称:emission,代码行数:50,代码来源:index.ts


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