Skip to content

Commit

Permalink
Example implementation by querying for a Github PR associated with a …
Browse files Browse the repository at this point in the history
…check request (#16)
  • Loading branch information
swcollard authored Nov 1, 2024
1 parent 8bb797e commit 9146b97
Show file tree
Hide file tree
Showing 5 changed files with 441 additions and 820 deletions.
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This example Netlify function does the following:

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).

## Installation
### Installation

1. Set up a Netlify account, then install and authenticate with [Netlify CLI](https://docs.netlify.com/cli/get-started/).
1. Install dependencies and build function code. `$ npm install ; npm run build`
Expand All @@ -30,7 +30,42 @@ After building and deploying the function, you need to [enable custom schema che
- The `APOLLO_HMAC_TOKEN` should be any string that will be used to calculate the `x-apollo-signature header`.
- 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.
1. Deploy the function to production. `$ netlify deploy --prod`
1. From your terminal, copy the **Website URL** plus the path `/custom-lint` and go to [GraphOS Studio](https://studio.apollographql.com/).
1. From your terminal, copy the **Website URL** plus the path `/custom-check` and go to [GraphOS Studio](https://studio.apollographql.com/).
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.
1. Run a schema check using the [Rover CLI](https://www.apollographql.com/docs/rover/) to test the integration.
- You should see check results in GraphOS Studio on the **Checks** page. You can also verify logs in the Netlify console.


## Example Github PR implementation

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).

This example Netlify function does the following:

- Receives the [webhook payload](http://localhost:3000/graphos/delivery/custom-checks#webhook-format) from GraphOS.
- Validates the HMAC value in the `x-apollo-signature` header.
- Downloads the composed supergraph.
- Queries the Github GraphQL API to fetch pull requests for the branch associated with the schema check
- 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.

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).

### Installation

1. Set up a Netlify account, then install and authenticate with [Netlify CLI](https://docs.netlify.com/cli/get-started/).
1. Select the github implementation in `index.ts` by uncommenting exporting `pullRequestCheck` and commenting out exporting `customLint`.
1. Install dependencies and build function code. `$ npm install ; npm run build`
1. To deploy to Netlify, follow the CLI instructions for creating and configuring a new site. `$ netlify deploy`
- 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.
1. Pull up site you created in the [Netlify web console](https://app.netlify.com/).
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`.
- The `APOLLO_HMAC_TOKEN` should be any string that will be used to calculate the `x-apollo-signature header`.
- 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.
- The `GITHUB_OWNER` should be the name of the owner of the repository.
- The `GITHUB_REPO` is the name of the repository.
- The `GITHUB_TOKEN` is a personal access token that should have read permissions for pull requests in the repository.
1. Deploy the function to production. `$ netlify deploy --prod`
1. From your terminal, copy the **Website URL** plus the path `/custom-check` and go to [GraphOS Studio](https://studio.apollographql.com/).
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.
1. Run a schema check using the [Rover CLI](https://www.apollographql.com/docs/rover/) to test the integration.
- You should see check results in GraphOS Studio on the **Checks** page. You can also verify logs in the Netlify console.
Loading

0 comments on commit 9146b97

Please sign in to comment.