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 registered 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
- Client-side schema extensions wrapped in the
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.
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:
$ apollo client:check --variant=production
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 jobs: # ...other jobs... # Define a separate job for each environment you validate against. check_against_staging: docker: - image: circleci/node:12 steps: - 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