Validating Client Operations

Confirm that all client operations are supported by your schema


You can confirm that all of the GraphQL operations defined in your client application are valid against the types, fields, and arguments in your graph's published schema. To do so, you use the apollo client:check command of the Apollo CLI:

Text
1$ apollo client:check
2
3  ✔ Loading Apollo Project
4  ✔ Checking client compatibility with service
5
6GetTeamGrid: src/components/TeamGrid.jsx:4
7
8    FAILURE    Field "league" must not have a selection since type "SportsLeague" has no subfields.
9
104 total operations validated
111 failure

You run this command from your client application's root. It recursively scans your project for the following:

By combining your registered graph's schema with your client-side schema extensions, the apollo client:check command can confirm whether the shape of each defined operation conforms to the shape of your combined schema.

Make sure that your project provides a graph API key to the Apollo CLI. This both authenticates the CLI with Studio and specifies which graph's schema you're checking against.

Checking against a particular variant

During development, your application might be executing GraphQL operations against a locally running server with a schema that differs somewhat from your production server's schema. Because schemas can differ, it's important to always check your operations against the current schema for a particular environment before you push client changes to that environment.

If you represent each of your server's environments with a separate graph variant (recommended), you can check your operations against a particular variant's schema like so:

Text
1$ apollo client:check --variant=production

Using with continuous integration

Your application can incorporate client:check into its continuous delivery pipeline to help ensure that new and modified operations are valid before they go live.

Here's a Circle CI configuration excerpt that incorporates the command:

YAML
config.yml
1version: 2
2
3jobs:
4  # ...other jobs...
5
6  # Define a separate job for each environment you validate against.
7  check_against_staging:
8    docker:
9      - image: circleci/node:12
10
11    steps:
12      - checkout
13
14      - run: npm install
15
16      # CircleCI needs global installs to be sudo
17      - run: sudo npm install --global apollo
18
19      # This command authenticates using the `APOLLO_KEY` environment variable.
20      # Don't forget to provide your API key in it.
21      - run: npx apollo client:check --variant=staging
Feedback

Edit on GitHub

Forums