Skip to content

Commit 9146b97

Browse files
authored
Example implementation by querying for a Github PR associated with a check request (#16)
1 parent 8bb797e commit 9146b97

File tree

5 files changed

+441
-820
lines changed

5 files changed

+441
-820
lines changed

README.md

+37-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This example Netlify function does the following:
1919

2020
After building and deploying the function, you need to [enable custom schema checks and register the function endpoint in GraphOS Studio](https://www.apollographql.com/docs/graphos/delivery/custom-checks#enable-custom-checks-in-studio).
2121

22-
## Installation
22+
### Installation
2323

2424
1. Set up a Netlify account, then install and authenticate with [Netlify CLI](https://docs.netlify.com/cli/get-started/).
2525
1. Install dependencies and build function code. `$ npm install ; npm run build`
@@ -30,7 +30,42 @@ After building and deploying the function, you need to [enable custom schema che
3030
- The `APOLLO_HMAC_TOKEN` should be any string that will be used to calculate the `x-apollo-signature header`.
3131
- The `APOLLO_API_KEY` is a [GraphOS API key](https://www.apollographql.com/docs/graphos/api-keys/) with sufficient permissions to run schema checks for the graph you're integrating this application with.
3232
1. Deploy the function to production. `$ netlify deploy --prod`
33-
1. From your terminal, copy the **Website URL** plus the path `/custom-lint` and go to [GraphOS Studio](https://studio.apollographql.com/).
33+
1. From your terminal, copy the **Website URL** plus the path `/custom-check` and go to [GraphOS Studio](https://studio.apollographql.com/).
34+
1. In the graph you're integrating this with go to **Checks > Configuration** and enable custom checks, registering the function URL and entering your `APOLLO_HMAC_TOKEN` as the secret token.
35+
1. Run a schema check using the [Rover CLI](https://www.apollographql.com/docs/rover/) to test the integration.
36+
- You should see check results in GraphOS Studio on the **Checks** page. You can also verify logs in the Netlify console.
37+
38+
39+
## Example Github PR implementation
40+
41+
This example implementation also deploys a [Netlify function](https://www.netlify.com/platform/core/functions/) that can be used to set up a webhook integration with GraphOS [schema checks](https://www.apollographql.com/docs/graphos/delivery/schema-checks).
42+
43+
This example Netlify function does the following:
44+
45+
- Receives the [webhook payload](http://localhost:3000/graphos/delivery/custom-checks#webhook-format) from GraphOS.
46+
- Validates the HMAC value in the `x-apollo-signature` header.
47+
- Downloads the composed supergraph.
48+
- Queries the Github GraphQL API to fetch pull requests for the branch associated with the schema check
49+
- If a pull request is found, a success message is returned to GraphOS. If no pull requests are found for the branch, a failure is returned.
50+
51+
After building and deploying the function, you need to [enable custom schema checks and register the function endpoint in GraphOS Studio](https://www.apollographql.com/docs/graphos/delivery/custom-checks#enable-custom-checks-in-studio).
52+
53+
### Installation
54+
55+
1. Set up a Netlify account, then install and authenticate with [Netlify CLI](https://docs.netlify.com/cli/get-started/).
56+
1. Select the github implementation in `index.ts` by uncommenting exporting `pullRequestCheck` and commenting out exporting `customLint`.
57+
1. Install dependencies and build function code. `$ npm install ; npm run build`
58+
1. To deploy to Netlify, follow the CLI instructions for creating and configuring a new site. `$ netlify deploy`
59+
- When asked for the publish directory, use the default root directory. The `netlify.toml` file has a pointer to the `dist/` to upload the built function.
60+
1. Pull up site you created in the [Netlify web console](https://app.netlify.com/).
61+
1. In the Netlify console, go to **Site configuration > Environment variables**. Add and upload values for the environment variables: `APOLLO_HMAC_TOKEN`, `APOLLO_API_KEY`, `GITHUB_OWNER`, `GITHUB_REPO`, and `GITHUB_TOKEN`.
62+
- The `APOLLO_HMAC_TOKEN` should be any string that will be used to calculate the `x-apollo-signature header`.
63+
- The `APOLLO_API_KEY` is a [GraphOS API key](https://www.apollographql.com/docs/graphos/api-keys/) with sufficient permissions to run schema checks for the graph you're integrating this application with.
64+
- The `GITHUB_OWNER` should be the name of the owner of the repository.
65+
- The `GITHUB_REPO` is the name of the repository.
66+
- The `GITHUB_TOKEN` is a personal access token that should have read permissions for pull requests in the repository.
67+
1. Deploy the function to production. `$ netlify deploy --prod`
68+
1. From your terminal, copy the **Website URL** plus the path `/custom-check` and go to [GraphOS Studio](https://studio.apollographql.com/).
3469
1. In the graph you're integrating this with go to **Checks > Configuration** and enable custom checks, registering the function URL and entering your `APOLLO_HMAC_TOKEN` as the secret token.
3570
1. Run a schema check using the [Rover CLI](https://www.apollographql.com/docs/rover/) to test the integration.
3671
- You should see check results in GraphOS Studio on the **Checks** page. You can also verify logs in the Netlify console.

0 commit comments

Comments
 (0)