|
1 |
| -# custom-check-examples |
2 |
| -Repository with a sample applications for implementing a GraphOS Schema Check webhook integration |
| 1 | +# Custom schema check webhook examples |
3 | 2 |
|
4 |
| -**The code in this repository is experimental and has been provided for reference purposes only. Community feedback is welcome but this project may not be supported in the same way that repositories in the official [Apollo GraphQL GitHub organization](https://github.com/apollographql) are. If you need help you can file an issue on this repository, [contact Apollo](https://www.apollographql.com/contact-sales) to talk to an expert, or create a ticket directly in Apollo Studio.** |
| 3 | +This repository contains a sample validation service for GraphOS [custom schema check](https://www.apollographql.com/docs/graphos/delivery/custom-checks). |
5 | 4 |
|
6 |
| -TK Link to Custom Check Documentation |
| 5 | +> [!NOTE] |
| 6 | +> The code in this repository is experimental and has been provided for reference purposes only. This repository may not be supported in the same way that repositories in the official [Apollo GraphQL GitHub organization](https://github.com/apollographql) are. If you need help, you can file an issue on this repository, [contact Apollo Support](https://support.apollographql.com/), or create a ticket directly in [GraphOS Studio](https://studio.apollographql.com/). |
7 | 7 |
|
8 |
| -## Netlify Function |
| 8 | +## Example graphql-eslint implementation |
9 | 9 |
|
10 |
| -This implementation is to deploy a [netlify function](https://www.netlify.com/platform/core/functions/) that can be used to set up an integration with GraphOS Schema Checks. After building and deploying the function, configure your schema checks in Apollo Studio to tell GraphOS to notify your endpoint during each schema check. |
| 10 | +This example implementation 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). |
11 | 11 |
|
12 |
| -This sample implementation will receive the webhook payload (*TK link to docs*) from GraphOS, validate the HMAC value in the `x-apollo-signature` header, download the composed supergraph, and lint the schema using graphql-eslint. Finally it will upload any violations found by the linter back to GraphOS to complete the custom check task. |
| 12 | +This example Netlify function does the following: |
| 13 | +- Receives the [webhook payload](http://localhost:3000/graphos/delivery/custom-checks#webhook-format) from GraphOS. |
| 14 | +- Validates the HMAC value in the `x-apollo-signature` header. |
| 15 | +- Downloads the composed supergraph. |
| 16 | +- Lints the schema using [graphql-eslint](https://github.com/dimaMachina/graphql-eslint#readme). |
| 17 | +- Uploads any linter violations back to GraphOS to complete the custom check task. |
13 | 18 |
|
14 |
| -### Instructions |
| 19 | +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). |
15 | 20 |
|
16 |
| -1. Set up a netlify account, then install and authenticate with [netlify CLI](https://docs.netlify.com/cli/get-started/) |
17 |
| -2. Install dependencies and build function code. `$ npm install ; npm run build` |
18 |
| -3. Deploy to netlify, follow CLI instructions for creating and configuring a new site. `$ netlify deploy` |
19 |
| -4. Publish using the root directory. The `netlify.toml` file has a pointer to the `dist/` to upload the built function. |
20 |
| -5. Pull up the function in the Netlify web console. Navigate to "Site configuration > Environment variables" |
21 |
| -6. Upload values for the environment variables `APOLLO_HMAC_TOKEN` and `APOLLO_API_KEY`. The HMAC token should be any String that will be used to calculate the x-apollo-signature header. The API key should have sufficient permissions to run schema checks for the Graph you are integrating this application with. |
22 |
| -7. Deploy function to production. `$ netlify deploy --prod` |
23 |
| -8. Copy the fuction url plus the path `/custom-lint` and go to Apollo Studio. |
24 |
| -9. Navigate to the custom check configuration for your graph and add a webhook integration for the function url and secret token. |
25 |
| -10. Test the integration in Studio and verify the logs in the netlify console. Then using [rover](https://www.apollographql.com/docs/rover/) submit a schema check and verify the logs in netlify console as well as the checks page in Studio. |
| 21 | +## Installation |
| 22 | + |
| 23 | +1. Set up a Netlify account, then install and authenticate with [Netlify CLI](https://docs.netlify.com/cli/get-started/). |
| 24 | +1. Install dependencies and build function code. `$ npm install ; npm run build` |
| 25 | +1. To deploy to Netlify, follow the CLI instructions for creating and configuring a new site. `$ netlify deploy` |
| 26 | + - 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. |
| 27 | +1. Pull up site you created in the [Netlify web console](https://app.netlify.com/). |
| 28 | +1. In the Netlify console, go to **Site configuration > Environment variables**. Add and upload values for the environment variables: `APOLLO_HMAC_TOKEN` and `APOLLO_API_KEY`. |
| 29 | + - The `APOLLO_HMAC_TOKEN` should be any string that will be used to calculate the `x-apollo-signature header`. |
| 30 | + - 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. |
| 31 | +1. Deploy the function to production. `$ netlify deploy --prod` |
| 32 | +1. From your terminal, copy the **Website URL** plus the path `/custom-lint` and go to [GraphOS Studio](https://studio.apollographql.com/). |
| 33 | +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. |
| 34 | +1. Run a schema check using the [Rover CLI](https://www.apollographql.com/docs/rover/) to test the integration. |
| 35 | + - You should see check results in GraphOS Studio on the **Checks** page. You can also verify logs in the Netlify console. |
0 commit comments