• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript apollo-server-errors.formatApolloErrors函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: it

    it('provides a user input error', () => {
      const error = new UserInputError(message, {
        field1: 'property1',
        field2: 'property2',
      });
      verifyError(error, {
        code: 'BAD_USER_INPUT',
        errorClass: UserInputError,
        name: 'UserInputError',
      });

      const formattedError = formatApolloErrors([
        new GraphQLError(
          error.message,
          undefined,
          undefined,
          undefined,
          undefined,
          error,
        ),
      ])[0];

      expect(formattedError.extensions.exception.field1).toEqual('property1');
      expect(formattedError.extensions.exception.field2).toEqual('property2');
    });
开发者ID:apollostack,项目名称:apollo-server,代码行数:25,代码来源:errors.test.ts


示例2: formatApolloErrors

const createFormatResponse = (formatter: (e: any) => any) => (response: any) => {
  const {errors = null} = response || {}

  return {
    ...response,
    errors: Array.isArray(errors) ? formatApolloErrors(errors, {formatter}) : undefined,
  }
}
开发者ID:vtex,项目名称:apps-client-node,代码行数:8,代码来源:formatters.ts


示例3: buildRequestContext

 requests.map(async request => {
   try {
     const requestContext = buildRequestContext(request);
     return await processGraphQLRequest(options, requestContext);
   } catch (error) {
     // A batch can contain another query that returns data,
     // so we don't error out the entire request with an HttpError
     return {
       errors: formatApolloErrors([error], options),
     };
   }
 }),
开发者ID:apollostack,项目名称:apollo-server,代码行数:12,代码来源:runHttpQuery.ts


示例4: ApolloError

 const createFormattedError: CreateFormatError = (
   options?: Record<string, any>,
   errors?: Error[],
 ) => {
   if (errors === undefined) {
     const error = new ApolloError(message, code, { key });
     return formatApolloErrors(
       [
         new GraphQLError(
           error.message,
           undefined,
           undefined,
           undefined,
           undefined,
           error,
         ),
       ],
       options,
     )[0];
   } else {
     return formatApolloErrors(errors, options);
   }
 };
开发者ID:apollostack,项目名称:apollo-server,代码行数:23,代码来源:errors.test.ts


示例5: willSendResponse

 public willSendResponse(o: {
   graphqlResponse: GraphQLResponse;
 }): void | { graphqlResponse: GraphQLResponse } {
   if (o.graphqlResponse.errors) {
     return {
       graphqlResponse: {
         ...o.graphqlResponse,
         errors: formatApolloErrors(o.graphqlResponse.errors, {
           formatter: this.formatError,
           debug: this.debug,
         }),
       },
     };
   }
 }
开发者ID:simonjoom,项目名称:react-native-project,代码行数:15,代码来源:formatters.ts


示例6: HttpQueryError

/**
 * If options is specified, then the errors array will be formatted
 */
function throwHttpGraphQLError<E extends Error>(
  statusCode: number,
  errors: Array<E>,
  options?: Pick<GraphQLOptions, 'debug' | 'formatError'>,
): never {
  throw new HttpQueryError(
    statusCode,
    prettyJSONStringify({
      errors: options
        ? formatApolloErrors(errors, {
            debug: options.debug,
            formatter: options.formatError,
          })
        : errors,
    }),
    true,
    {
      'Content-Type': 'application/json',
    },
  );
}
开发者ID:apollostack,项目名称:apollo-server,代码行数:24,代码来源:runHttpQuery.ts


示例7: formatApolloErrors

          .then(result => {
            let response: GraphQLResponse = {
              data: result.data,
            };

            if (result.errors) {
              response.errors = formatApolloErrors([...result.errors], {
                debug,
              });
            }

            executionDidEnd(...(result.errors || []));

            const formattedExtensions = extensionStack.format();
            if (Object.keys(formattedExtensions).length > 0) {
              response.extensions = formattedExtensions;
            }

            if (options.formatResponse) {
              response = options.formatResponse(response, options);
            }

            return response;
          });
开发者ID:simonjoom,项目名称:react-native-project,代码行数:24,代码来源:runQuery.ts


示例8: if

      (): Promise<GraphQLResponse> => {
        // Parse the document.
        let documentAST: DocumentNode;
        if (options.parsedQuery) {
          documentAST = options.parsedQuery;
        } else if (!options.queryString) {
          throw new Error('Must supply one of queryString and parsedQuery');
        } else {
          const parsingDidEnd = extensionStack.parsingDidStart({
            queryString: options.queryString,
          });
          let graphqlParseErrors: SyntaxError[] | undefined;
          try {
            documentAST = parse(options.queryString);
          } catch (syntaxError) {
            graphqlParseErrors = formatApolloErrors(
              [
                fromGraphQLError(syntaxError, {
                  errorClass: SyntaxError,
                }),
              ],
              {
                debug,
              },
            );
            return Promise.resolve({ errors: graphqlParseErrors });
          } finally {
            parsingDidEnd(...(graphqlParseErrors || []));
          }
        }

        if (
          options.nonQueryError &&
          !isQueryOperation(documentAST, options.operationName)
        ) {
          // XXX this goes to requestDidEnd, is that correct or should it be
          // validation?
          throw options.nonQueryError;
        }

        let rules = specifiedRules;
        if (options.validationRules) {
          rules = rules.concat(options.validationRules);
        }
        const validationDidEnd = extensionStack.validationDidStart();
        let validationErrors: GraphQLError[] | undefined;
        try {
          validationErrors = validate(
            options.schema,
            documentAST,
            rules,
          ) as GraphQLError[]; // Return type of validate is ReadonlyArray<GraphQLError>
        } catch (validationThrewError) {
          // Catch errors thrown by validate, not just those returned by it.
          validationErrors = [validationThrewError];
        } finally {
          try {
            if (validationErrors) {
              validationErrors = formatApolloErrors(
                validationErrors.map(err =>
                  fromGraphQLError(err, { errorClass: ValidationError }),
                ),
                {
                  debug,
                },
              );
            }
          } finally {
            validationDidEnd(...(validationErrors || []));

            if (validationErrors && validationErrors.length) {
              return Promise.resolve({
                errors: validationErrors,
              });
            }
          }
        }

        const executionArgs: ExecutionArgs = {
          schema: options.schema,
          document: documentAST,
          rootValue: options.rootValue,
          contextValue: context,
          variableValues: options.variables,
          operationName: options.operationName,
          fieldResolver: options.fieldResolver,
        };
        const executionDidEnd = extensionStack.executionDidStart({
          executionArgs,
        });
        return Promise.resolve()
          .then(() => execute(executionArgs))
          .catch(executionError => {
            return {
              // These errors will get passed through formatApolloErrors in the
              // `then` below.
              // TODO accurate code for this error, which describes this error, which
              // can occur when:
              // * variables incorrectly typed/null when nonnullable
              // * unknown operation/operation name invalid
//.........这里部分代码省略.........
开发者ID:simonjoom,项目名称:react-native-project,代码行数:101,代码来源:runQuery.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap