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

TypeScript graphql-playground-html.renderPlaygroundPage函数代码示例

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

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



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

示例1: handleGraphqlRequestsWithPlayground

  // If the `playgroundOptions` are set, register a `graphql-playground` instance
  // (not available in production) that is then used to handle all
  // incoming GraphQL requests.
  private handleGraphqlRequestsWithPlayground({
    req,
    res,
  }: {
    req: MicroRequest;
    res: ServerResponse;
  }): boolean {
    let handled = false;

    if (this.playgroundOptions && req.method === 'GET') {
      const accept = parseAll(req.headers);
      const types = accept.mediaTypes as string[];
      const prefersHTML =
        types.find(
          (x: string) => x === 'text/html' || x === 'application/json',
        ) === 'text/html';

      if (prefersHTML) {
        const middlewareOptions = {
          endpoint: this.graphqlPath,
          subscriptionEndpoint: this.subscriptionsPath,
          ...this.playgroundOptions,
        };
        send(res, 200, renderPlaygroundPage(middlewareOptions));
        handled = true;
      }
    }

    return handled;
  }
开发者ID:simonjoom,项目名称:react-native-project,代码行数:33,代码来源:ApolloServer.ts


示例2: renderPlaygroundPage

            (
              req: FastifyRequest<IncomingMessage>,
              reply: FastifyReply<OutgoingMessage>,
              done: () => void,
            ) => {
              // Note: if you enable playground in production and expect to be able to see your
              // schema, you'll need to manually specify `introspection: true` in the
              // ApolloServer constructor; by default, the introspection query is only
              // enabled in dev.
              if (this.playgroundOptions && req.req.method === 'GET') {
                // perform more expensive content-type check only if necessary
                const accept = (req as any).accepts() as Accepts;
                const types = accept.types() as string[];
                const prefersHTML =
                  types.find(
                    (x: string) =>
                      x === 'text/html' || x === 'application/json',
                  ) === 'text/html';

                if (prefersHTML) {
                  const playgroundRenderPageOptions: PlaygroundRenderPageOptions = {
                    endpoint: this.graphqlPath,
                    subscriptionEndpoint: this.subscriptionsPath,
                    ...this.playgroundOptions,
                  };
                  reply.type('text/html');
                  const playground = renderPlaygroundPage(
                    playgroundRenderPageOptions,
                  );
                  reply.send(playground);
                  return;
                }
              }
              done();
            },
开发者ID:apollostack,项目名称:apollo-server,代码行数:35,代码来源:ApolloServer.ts


示例3: middlewareFromPath

      middlewareFromPath(path, (ctx: Koa.Context, next: Function) => {
        if (ctx.request.method === 'OPTIONS') {
          ctx.status = 204;
          ctx.body = '';
          return;
        }

        if (this.playgroundOptions && ctx.request.method === 'GET') {
          // perform more expensive content-type check only if necessary
          const accept = accepts(ctx.req);
          const types = accept.types() as string[];
          const prefersHTML =
            types.find(
              (x: string) => x === 'text/html' || x === 'application/json',
            ) === 'text/html';

          if (prefersHTML) {
            const playgroundRenderPageOptions: PlaygroundRenderPageOptions = {
              endpoint: path,
              subscriptionEndpoint: this.subscriptionsPath,
              ...this.playgroundOptions,
            };
            ctx.set('Content-Type', 'text/html');
            const playground = renderPlaygroundPage(
              playgroundRenderPageOptions,
            );
            ctx.body = playground;
            return;
          }
        }

        return graphqlKoa(() => {
          return this.createGraphQLServerOptions(ctx);
        })(ctx, next);
      }),
开发者ID:apollostack,项目名称:apollo-server,代码行数:35,代码来源:ApolloServer.ts


示例4: function

      method: async function(request, h) {
        if (request.path !== path) {
          return h.continue;
        }

        if (this.uploadsConfig && typeof processFileUploads === 'function') {
          await handleFileUploads(this.uploadsConfig)(request);
        }

        if (this.playgroundOptions && request.method === 'get') {
          // perform more expensive content-type check only if necessary
          const accept = parseAll(request.headers);
          const types = accept.mediaTypes as string[];
          const prefersHTML =
            types.find(
              (x: string) => x === 'text/html' || x === 'application/json',
            ) === 'text/html';

          if (prefersHTML) {
            const playgroundRenderPageOptions: PlaygroundRenderPageOptions = {
              endpoint: path,
              subscriptionEndpoint: this.subscriptionsPath,
              version: this.playgroundVersion,
              ...this.playgroundOptions,
            };

            return h
              .response(renderPlaygroundPage(playgroundRenderPageOptions))
              .type('text/html')
              .takeover();
          }
        }
        return h.continue;
      }.bind(this),
开发者ID:apollostack,项目名称:apollo-server,代码行数:34,代码来源:ApolloServer.ts


示例5: accepts

    app.use(path, (req, res, next) => {
      if (this.playgroundOptions && req.method === 'GET') {
        // perform more expensive content-type check only if necessary
        // XXX We could potentially move this logic into the GuiOptions lambda,
        // but I don't think it needs any overriding
        const accept = accepts(req);
        const types = accept.types() as string[];
        const prefersHTML =
          types.find(
            (x: string) => x === 'text/html' || x === 'application/json',
          ) === 'text/html';

        if (prefersHTML) {
          const playgroundRenderPageOptions: PlaygroundRenderPageOptions = {
            endpoint: path,
            subscriptionEndpoint: this.subscriptionsPath,
            ...this.playgroundOptions,
          };
          res.setHeader('Content-Type', 'text/html');
          const playground = renderPlaygroundPage(playgroundRenderPageOptions);
          res.write(playground);
          res.end();
          return;
        }
      }
      return graphqlExpress(() => {
        return this.createGraphQLServerOptions(req, res);
      })(req, res, next);
    });
开发者ID:apollostack,项目名称:apollo-server,代码行数:29,代码来源:ApolloServer.ts


示例6: return

    return (context: HttpContext, req: FunctionRequest) => {
      if (cors && cors.origin) {
        if (typeof cors.origin === 'string') {
          corsHeaders['Access-Control-Allow-Origin'] = cors.origin;
        } else if (
          typeof cors.origin === 'boolean' ||
          (Array.isArray(cors.origin) &&
            cors.origin.includes(
              req.headers['Origin'] || req.headers['origin'],
            ))
        ) {
          corsHeaders['Access-Control-Allow-Origin'] =
            req.headers['Origin'] || req.headers['origin'];
        }

        if (!cors.allowedHeaders) {
          corsHeaders['Access-Control-Allow-Headers'] =
            req.headers['Access-Control-Request-Headers'];
        }
      }

      if (req.method === 'OPTIONS') {
        context.done(null, {
          body: '',
          status: 204,
          headers: corsHeaders,
        });
        return;
      }

      if (this.playgroundOptions && req.method === 'GET') {
        const acceptHeader = req.headers['Accept'] || req.headers['accept'];
        if (acceptHeader && acceptHeader.includes('text/html')) {
          const path = req.originalUrl || '/';

          const playgroundRenderPageOptions: PlaygroundRenderPageOptions = {
            endpoint: path,
            ...this.playgroundOptions,
          };
          const body = renderPlaygroundPage(playgroundRenderPageOptions);
          context.done(null, {
            body: body,
            status: 200,
            headers: {
              'Content-Type': 'text/html',
              ...corsHeaders,
            },
          });
          return;
        }
      }

      const callbackFilter = (error?: any, output?: FunctionResponse) => {
        context.done(
          error,
          output && {
            ...output,
            headers: {
              ...output.headers,
              ...corsHeaders,
            },
          },
        );
      };
      graphqlAzureFunction(async () => {
        await promiseWillStart;
        return this.createGraphQLServerOptions(req, context);
      })(context, req, callbackFilter);
    };
开发者ID:apollostack,项目名称:apollo-server,代码行数:69,代码来源:ApolloServer.ts


示例7: return

    return (
      event: APIGatewayProxyEvent,
      context: LambdaContext,
      callback: APIGatewayProxyCallback,
    ) => {
      if (cors && cors.origin) {
        if (typeof cors.origin === 'string') {
          corsHeaders['Access-Control-Allow-Origin'] = cors.origin;
        } else if (
          typeof cors.origin === 'boolean' ||
          (Array.isArray(cors.origin) &&
            cors.origin.includes(
              event.headers['Origin'] || event.headers['origin'],
            ))
        ) {
          corsHeaders['Access-Control-Allow-Origin'] =
            event.headers['Origin'] || event.headers['origin'];
        }

        if (!cors.allowedHeaders) {
          corsHeaders['Access-Control-Allow-Headers'] =
            event.headers['Access-Control-Request-Headers'];
        }
      }

      if (event.httpMethod === 'OPTIONS') {
        return callback(null, {
          body: '',
          statusCode: 204,
          headers: corsHeaders,
        });
      }

      if (this.playgroundOptions && event.httpMethod === 'GET') {
        const acceptHeader = event.headers['Accept'] || event.headers['accept'];
        if (acceptHeader && acceptHeader.includes('text/html')) {
          const path =
            event.path ||
            (event.requestContext && event.requestContext.path) ||
            '/';

          const playgroundRenderPageOptions: PlaygroundRenderPageOptions = {
            endpoint: path,
            ...this.playgroundOptions,
          };

          return callback(null, {
            body: renderPlaygroundPage(playgroundRenderPageOptions),
            statusCode: 200,
            headers: {
              'Content-Type': 'text/html',
              ...corsHeaders,
            },
          });
        }
      }

      const callbackFilter: APIGatewayProxyCallback = (error, result) => {
        callback(
          error,
          result && {
            ...result,
            headers: {
              ...result.headers,
              ...corsHeaders,
            },
          },
        );
      };

      graphqlLambda(async () => {
        // In a world where this `createHandler` was async, we might avoid this
        // but since we don't want to introduce a breaking change to this API
        // (by switching it to `async`), we'll leverage the
        // `GraphQLServerOptions`, which are dynamically built on each request,
        // to `await` the `promiseWillStart` which we kicked off at the top of
        // this method to ensure that it runs to completion (which is part of
        // its contract) prior to processing the request.
        await promiseWillStart;
        return this.createGraphQLServerOptions(event, context);
      })(event, context, callbackFilter);
    };
开发者ID:apollostack,项目名称:apollo-server,代码行数:82,代码来源:ApolloServer.ts


示例8: return

    return (req: Request, res: Response) => {
      // Handle both the root of the GCF endpoint and /graphql
      // With bare endpoints, GCF sets request params' path to null.
      // The check for '' is included in case that behaviour changes
      if (req.path && !['', '/', '/graphql'].includes(req.path)) {
        res.status(404).end();
        return;
      }

      if (cors) {
        if (typeof cors.origin === 'string') {
          res.set('Access-Control-Allow-Origin', cors.origin);
        } else if (
          typeof cors.origin === 'boolean' ||
          (Array.isArray(cors.origin) &&
            cors.origin.includes(req.get('origin') || ''))
        ) {
          res.set('Access-Control-Allow-Origin', req.get('origin'));
        }

        if (!cors.allowedHeaders) {
          res.set(
            'Access-Control-Allow-Headers',
            req.get('Access-Control-Request-Headers'),
          );
        }
      }

      if (req.method === 'OPTIONS') {
        res.status(204).send('');
        return;
      }

      if (this.playgroundOptions && req.method === 'GET') {
        const acceptHeader = req.headers['accept'] as string;
        if (acceptHeader && acceptHeader.includes('text/html')) {
          const playgroundRenderPageOptions: PlaygroundRenderPageOptions = {
            endpoint: req.get('referer'),
            ...this.playgroundOptions,
          };

          res
            .status(200)
            .send(renderPlaygroundPage(playgroundRenderPageOptions));
          return;
        }
      }

      res.set(corsHeaders);

      graphqlCloudFunction(async () => {
        // In a world where this `createHandler` was async, we might avoid this
        // but since we don't want to introduce a breaking change to this API
        // (by switching it to `async`), we'll leverage the
        // `GraphQLServerOptions`, which are dynamically built on each request,
        // to `await` the `promiseWillStart` which we kicked off at the top of
        // this method to ensure that it runs to completion (which is part of
        // its contract) prior to processing the request.
        await promiseWillStart;
        return this.createGraphQLServerOptions(req, res);
      })(req, res);
    };
开发者ID:apollostack,项目名称:apollo-server,代码行数:62,代码来源:ApolloServer.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript app.reducers类代码示例发布时间:2022-05-28
下一篇:
TypeScript geometry.vector类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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