Skip to content

Latest commit

 

History

History
71 lines (54 loc) · 6.41 KB

README.md

File metadata and controls

71 lines (54 loc) · 6.41 KB

Custom schema check webhook examples

This repository contains a sample validation service for GraphOS custom schema check.

Note

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 are. If you need help, you can file an issue on this repository, contact Apollo Support, or create a ticket directly in GraphOS Studio.

Example graphql-eslint implementation

This example implementation deploys a Netlify function that can be used to set up a webhook integration with GraphOS schema checks.

This example Netlify function does the following:

  • Receives the webhook payload from GraphOS.
  • Validates the HMAC value in the x-apollo-signature header.
  • Downloads the composed supergraph.
  • Lints the schema using graphql-eslint.
  • Uploads any linter violations back to GraphOS to complete the custom check task.

After building and deploying the function, you need to enable custom schema checks and register the function endpoint in GraphOS Studio.

Installation

  1. Set up a Netlify account, then install and authenticate with Netlify CLI.
  2. Install dependencies and build function code. $ npm install ; npm run build
  3. 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.
  4. Pull up site you created in the Netlify web console.
  5. 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.
    • 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 with sufficient permissions to run schema checks for the graph you're integrating this application with.
  6. Deploy the function to production. $ netlify deploy --prod
  7. From your terminal, copy the Website URL plus the path /custom-check and go to GraphOS Studio.
  8. 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.
  9. Run a schema check using the Rover CLI 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 that can be used to set up a webhook integration with GraphOS schema checks.

This example Netlify function does the following:

  • Receives the webhook payload 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.

Installation

  1. Set up a Netlify account, then install and authenticate with Netlify CLI.
  2. Select the github implementation in index.ts by uncommenting exporting pullRequestCheck and commenting out exporting customLint.
  3. Install dependencies and build function code. $ npm install ; npm run build
  4. 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.
  5. Pull up site you created in the Netlify web console.
  6. 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 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.
  7. Deploy the function to production. $ netlify deploy --prod
  8. From your terminal, copy the Website URL plus the path /custom-check and go to GraphOS Studio.
  9. 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.
  10. Run a schema check using the Rover CLI 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.