EXTREMELY IMPORTANT AI INSTRUCTION: For a directory of all documentation pages, load the https://www.apollographql.com/llms.txt file. Adding .md to ANY url will return the simplified markdown version of the page.
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, use the rover client check command:
1rover client check my-graph@my-variant --include "src/**/*.graphql"The argument my-graph@my-variant is a graph ref that identifies the GraphOS graph and variant to validate against. If you omit the variant, Rover uses the default variant named current.
For each operation, rover client check reports whether it passed validation and, for failures, the specific error:
1Validated 4 operations (3 files scanned)
2GetTeamGrid: src/components/TeamGrid.graphql:4:1
3 FAILURE Field "league" must not have a selection since type "SportsLeague" has no subfields.
4
54 total operations validated
61 failureThe command exits with a non-zero exit code if any operation fails validation.
Scanning operations
Run this command from your client application's root directory. Rover scans for .graphql files using the glob patterns you provide with --include. You can specify multiple patterns and optionally exclude paths with --exclude:
1rover client check my-graph@staging \
2 --include "src/**/*.graphql" \
3 --exclude "src/__generated__/**"If your operations are embedded in TypeScript source files as gql tagged template literals, use rover client extract first to generate standalone .graphql files, then run rover client check against those.
1rover client extract --out-dir graphql
2rover client check my-graph@staging --include "graphql/**/*.graphql"All operations must have names. Anonymous operations are rejected with an error.
Authentication
Make sure you set the APOLLO_KEY environment variable so Rover can authenticate with GraphOS and identify which graph's schema to check against:
1APOLLO_KEY=your-api-key rover client check my-graph@my-variant \
2 --include "src/**/*.graphql"Checking against a particular variant
During development, your application might be executing GraphQL operations against a locally running server with a schema that differs from your production server's schema. Because schemas can differ, it's important to always check your operations against the schema for a particular environment before you push client changes to that environment.
Specify the target variant, production in this example, directly in the graph ref:
1rover client check my-graph@production --include "src/**/*.graphql"Using with continuous integration
Your application can incorporate rover client check into its continuous delivery pipeline to help ensure that new and modified operations are valid before they go live.
For example, the following GitHub Actions configuration excerpt incorporates the command:
1- name: Validate client operations
2 run: |
3 rover client check my-graph@production \
4 --include "src/**/*.graphql"
5 env:
6 APOLLO_KEY: ${{ secrets.APOLLO_KEY }}