This repository demonstrates how to integrate GitHub's GraphQL API with Azure API Management (APIM).
-
Create a GitHub Personal Access Token:
- Go to https://github.com/settings/tokens
- Click "Generate new token (classic)"
- Give it a descriptive name (e.g., "GraphQL Sample App")
- Select the following scopes:
read:user- to read user profile informationrepo- to access repository information (required for private repositories)
- Click "Generate token"
- Important: Copy the token immediately as you won't be able to see it again
-
Trigger the provisioning using
azd provision, the azd script will prompt for the thegithubTokenparameter
$ azd up
(✓) Done: Downloading Bicep
? Select an Azure Subscription to use: 26. external-bmoussaud-ms (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
? Enter a value for the 'githubToken' infrastructure secured parameter: [? for help] *********************************************************************************************
? Pick a resource group to use: 1. Create a new resource group
? Select a location to create the resource group in: 51. (US) East US 2 (eastus2)
? Enter a name for the new resource group: rg-graphql-dev
Packaging services (azd package)
Provisioning Azure resources (azd provision)
Provisioning Azure resources can take some time.
Subscription: external-xxxxxxxx-xx (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
You can view detailed progress in the Azure Portal:
https://portal.azure.com/#view/HubsExtension/DeploymentDetailsBlade/~/overview/id/%2Fsubscriptions%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%2FresourceGroups%2Frg-graphql-dev%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2Fdev-1762943049
(✓) Done: Log Analytics workspace: log-analytics-tgebslojbs6y2 (20.864s)
(✓) Done: Application Insights: app-insights-tgebslojbs6y2 (4.46s)
(✓) Done: Azure API Management: apim-tgebslojbs6y2 (1m8.741s)
- Settings
cd github-graphql-sample
azd env get-values > .env
source .envor manually
cd github-graphql-sample
export GITHUB_TOKEN=your_github_token
export GITHUB_GRAPHQL_API_URL=https://apim-rkh7dxqqe2ol4.azure-api.net/github-graphql
export GITHUB_APIM_SUBSCRIPTION_KEY=your_subscription_key- Test with curl using github_api:
curl -X POST "https://api.github.com/graphql" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"query": "{ viewer { login name } }"}'- Test with curl:
curl -X POST "${GITHUB_GRAPHQL_API_URL}" \
-H "Ocp-Apim-Subscription-Key: ${GITHUB_APIM_SUBSCRIPTION_KEY}" \
-H "Content-Type: application/json" \
-d '{"query": "{ viewer { login name } }"}'- Test with the Python client:
uv run python github_graphql_client.py viewerGet authenticated user info:
query {
viewer {
login
name
email
}
}Get repository information:
query {
repository(owner: "octocat", name: "Hello-World") {
name
description
stargazerCount
forkCount
}
}- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
