Integration with Google Cloud Platform
GraphQL Yoga v4 documentation (superseded by v5): Google Cloud Platform (GCP) is a suite of cloud computing services powered by Google. It is easy to use GraphQL Yoga with GCP.
Google Cloud Platform (GCP) is a suite of cloud computing services powered by Google. It is easy to use GraphQL Yoga with GCP.
Prerequisites
You will first need to install the GCP command-line tool: gcloud.
You can find instructions here.
If you already have gcloud installed, make sure it is up to date with gcloud components update.
Create a new project and make sure billing is enabled.
Cloud Functions
Cloud Functions is a serverless execution environment for building and connecting cloud services. With Cloud Functions, you write simple, single-purpose functions that are attached to events, such as an HTTP request.
It is probably the most straight forward way to deploy a Yoga server to GCP.
Installation
Usage
You can now deploy your function with gcloud CLI:
You can now test your function by using the URL found in the httpsTrigger.url property returned by
the previous command or by using the gcloud CLI:
You can also check a full example on our GitHub repository here
Cloud Run
Cloud Run is the Platform as a Service by Google. It is straightforward to use Yoga with it.
Installation
Create a new Node project and add Yoga to its dependencies.
Add a start script to your package.json. Cloud Run needs to know how to start your application.
Usage
Create a GraphQL server with your schema. You can use any HTTP server; here we will use Node’s HTTP implementation.
You can now deploy to Cloud Run. You can use all default values, except the last one, which allows unauthenticated access to your service.
You can now access your API using the URL provided by gcloud. The default GraphQL endpoint is
/graphql.
If you need to use TypeScript or any other tool that requires a build phase, such as code generation, add a Dockerfile to the root of your project so that Cloud Run can build a custom image for you.
You can also check a full example in our GitHub repository here