Giter Club home page Giter Club logo

graphql-check-action's Introduction

GraphQL Check

This action checks your GraphQL server health after deployment. Specifically, it will check:

  1. The endpoint is reachable
  2. Introspection is disabled (for non-federated graphs)
  3. Authentication is required to make any query
  4. If this is a federation subgraph, the subgraph contains required Federation elements

Inputs

Name Description Default
endpoint The full URL, including scheme (e.g., https://) of the GraphQL endpoint None
auth The full header to be included. Providing a value enables the "authentication required" check None
subgraph Whether the endpoint is expected to be a Federation subgraph false
allow_introspection Whether the GraphQL server should have introspection enabled. This should be disabled for non-subgraphs value of subgraph
insecure_subgraph Whether it is acceptable for your auth to be empty when subgraph is true. You generally don't want this false
token The GitHub token to use for GitHub API calls. May be needed if using this action very frequently. Workflow token

Tests

Here are all the tests that will run, and the config values that affect them.

Endpoint reachable

This action will always fail if making an HTTP POST request to the provided endpoint fails. The request will contain this query:

query {
    __typename
}

It expects this response:

{
  "data": {
    "__typename": "Query"
  }
}

If the auth parameter is provided, that header will be included in the request.

Introspection disabled

Generally speaking, introspection should be disabled for non-subgraphs. As such, by default this action will fail if the graph is not a [federated subgraph] (checked dynamically) and the server responds with some content to the following query:

query {
    __schema {
        types {
            name
        }
    }
}

If __schema in the response is null, this action will pass. You can bypass this check by setting allow_introspection to true.

Authentication enforced

If the auth input is provided, this action will fail if the GraphQL server responds successfully any query without the provided authentication. If the GraphQL server response with a non-200 status code or a GraphQL error, this action will pass.

If subgraph features are detected (by running the "Subgraph compatibility" check), but auth is not provided, this check will still fail, as an insecure subgraph is usually a mistake. If you need a public, insecure subgraph, you can provide the input insecure_subgraph: true.

Subgraph compatibility

If the subgraph input is set to true, this action will require that the endpoint is a federation subgraph. Specifically, it must return something for sdl in this query:

query {
    _service {
        sdl
    }
}

Examples

Standard GraphQL Server

Introspection is disabled and authentication is required for all operations.

name: Deploy
on:
  push:
    branches:
      - main
jobs:
  deploy:
    steps:
      - name: Deploy your server
      - name: Wait for deploy to finish
  check_graphql:
    runs-on: ubuntu-latest
    needs: deploy
    steps:
      - uses: actions/checkout@v3
      - uses: dbanty/[email protected]
        with:
          endpoint: ${{ vars.PRODUCTION_ENDPOINT }}
          auth: "Authorization: Bearer ${{ secrets.TEST_TOKEN }}"

Public GraphQL Server

While authentication may be required for operations, anyone is allowed to introspect the server and start building queries.

name: Deploy
on:
  push:
    branches:
      - main
jobs:
  deploy:
    steps:
      - name: Deploy your server
      - name: Wait for deploy to finish
  check_graphql:
    runs-on: ubuntu-latest
    needs: deploy
    steps:
      - uses: actions/checkout@v3
      - uses: dbanty/[email protected]
        with:
          endpoint: ${{ vars.PRODUCTION_ENDPOINT }}
          allow_introspection: true

Federated subgraph

This is the recommended setup for a federated subgraph which, generally speaking, should not be accessible to anything except the router.

name: Deploy
on:
  push:
    branches:
      - main
jobs:
  deploy:
    steps:
      - name: Deploy your server
      - name: Wait for deploy to finish
  check_graphql:
    runs-on: ubuntu-latest
    needs: deploy
    steps:
      - uses: actions/checkout@v3
      - uses: dbanty/[email protected]
        with:
          endpoint: ${{ vars.PRODUCTION_ENDPOINT }}
          auth: "Gateway-Authorization: Bearer ${{ secrets.AUTH_TOKEN }}"
          subgraph: true

graphql-check-action's People

Contributors

dbanty avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

graphql-check-action's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): lock file maintenance

Detected dependencies

cargo
Cargo.toml
  • itertools 0.13.0
  • ureq 2.9.7
  • serde_json 1.0.116
  • const_format 0.2.32
  • criterion 0.5.1
github-actions
.github/workflows/integration_tests.yml
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
.github/workflows/release.yml
  • actions/checkout v4.1.7
  • Swatinem/rust-cache v2
  • actions/upload-artifact v4.3.3
  • actions/checkout v4.1.7
  • actions/download-artifact v4.1.7
  • ncipollo/release-action v1.14.0
.github/workflows/rust_checks.yml
  • actions/checkout v4
  • actions/checkout v4
regex
rust-toolchain.toml
  • rust 1.79.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.