A serverless GraphQL API that is bundled with Kentico Cloud content resolution.
Note: you likely will need this repo also – https://github.com/MMTDigital/kentico-cloud-schema-generator-azure-function
This is an Azure Function that can be deployed and used as a GraphQL API for your application. It makes sense to be pulling content from Kentico Cloud into your application, but you are not restricted to this. Consider the following diagram:
- Clone this repo
- Install latest stable version of Node and Yarn
- Install dependencies:
yarn
- Run through the deployment process outlined below. Note, this may have already been done by your team, so check first
- Create a file at the root of the repo called
local.settings.json
and place this in it:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AZURE_STORAGE_CONNECTION_STRING": "",
"KENTICO_CLOUD_PROJECT_ID": "",
"FUNCTIONS_WORKER_RUNTIME": "",
"SCHEMA_STORAGE_CONTAINER_NAME": "",
"AZURE_STORAGE_BLOB_NAME": "",
}
}
Do not commit this file to the repo
- Populate the environment values. Check the env.json for a description of each.
- Finally, you can run and develop locally with
yarn start
The tool set to run and develop Azure Functions is provided by Azure Functions Core Tools. This has been installed as a dev dependency. To read more about these tools, check out the documentation: https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local
Avoid the temptation to install these tools globally on your system. Use the dev dependency and use npm scripts to run tasks. This keeps things running consistently across all machines.
Currently, this is a horrible manual process. It uses the Azure "Deployment Center" to set up:
- Sign in to the Azure Portal of choice: https://portal.azure.com
- Create a new Azure Function by clicking Create a resource and searching for "Function App". Set it up with the following values:
- App name:
{project}-kentico-cloud-graphql-server-{environment}
. For example:ciot-kentico-cloud-graphql-server-dev
- Resource Group: Select a resource group for the project (hopefully one should already exist)
- OS: Windows
- Hosting Plan: Consumption Plan
- Location: Central US
- Runtime Stack: JavaScript
- Storage: Create new (keep the ugly auto-generated name)
- Application Insights: Enabled
- App name:
- Once it's setup and deployed (this can take a few minutes) Click Function Apps
- Click the new function app and select the Platform features tab
- Click Deployment Center
- Select the repo provider that holds this forked repo
- Run through the next steps for CI / CD. This is slightly different per-provider
- If you are setting up a development environment, use the
dev
branch of the repo, otherwise use themaster
branch. How your branching strategy and deployment of the function works moving forward is up to you. There is a high chance that this function will never need to change at all.
Once you have set up a Function App within Azure, a Storage resource will be automatically created for you. You can find it in the Storage Accounts section. The name should match the auto-generated name in step 2. You will need to grab the connection string for this storage:
- Click the storage name
- Go to Access Keys
- Copy the connection string in
key1
Note: this connection string is confidential. It should not be checked into a repo and ideally not shared insecurely