Join us from October 8-10 in New York City to learn the latest tips, trends, and news about GraphQL Federation and API platform engineering.Join us for GraphQL Summit 2024 in NYC
Start for Free

Validating Client Operations

Confirm that all client operations are supported by your schema

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

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

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

  • GraphQL operations wrapped in the gql tag
  • Client-side schema extensions wrapped in the gql tag

By combining your registered 's schema with your client-side schema , the apollo client:check command can confirm whether the shape of each defined 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 's schema like so:

$ 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:

version: 2
# ...other jobs...
# Define a separate job for each environment you validate against.
- image: circleci/node:12
- checkout
- run: npm install
# CircleCI needs global installs to be sudo
- run: sudo npm install --global apollo
# This command authenticates using the `APOLLO_KEY` environment variable.
# Don't forget to provide your API key in it.
- run: npx apollo client:check --variant=staging
Moving to Rover
Rate articleRateEdit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc., d/b/a Apollo GraphQL.

Privacy Policy