當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。