【问题标题】:OpenAPI config for a Graphql backend using GCP API Gateway?使用 GCP API 网关的 Graphql 后端的 OpenAPI 配置?
【发布时间】:2021-06-26 21:15:52
【问题描述】:
【问题讨论】:
标签:
api
google-cloud-platform
graphql
openapi
api-gateway
【解决方案1】:
Here's a repo 展示了您想要实现的目标。它是一个 GCP API 网关,面向 Cloud Run 上的 GraphQL API,由 Identity-Aware Proxy 保护。以下是链接中的 API 配置:
api-spec.yaml
swagger: '2.0'
info:
title: gcp-demo-api
description: Sample GraphQL API on API Gateway with a Cloud Run backend
version: 1.0.0
schemes:
- https
produces:
- application/json
paths:
/:
post:
summary: GraphQL endpoint
operationId: gql
x-google-backend:
address: https://PROJECT_AND_RANDOM_STRING.a.run.app/graphql # App URL/endpoint
jwt_audience: LONG_RANDOM_STRING.apps.googleusercontent.com # IAP client ID
responses:
'200':
description: A successful response
schema:
type: object
要回答您的附带问题,了解 API 网关的作用很重要。 API 网关位于您的用户请求和您的后端服务集合之间,因此所有 API 请求都通过它。
因此,您无需为每个服务创建新的 API 网关。通过在每个端点上指定后端地址,API Gateway 可以提供多种服务,例如 Cloud Run、App Engine、Cloud Functions 等。这是一个link,进一步解释了这个概念。