| name | description |
|---|---|
rover-operation-builder |
Generate GraphQL operations (queries, mutations, subscriptions, fragments) using schemas fetched from Apollo GraphOS via Rover CLI. Use when the user wants to create GraphQL operations, write queries or mutations, build subscriptions, generate fragments, or needs help crafting GraphQL code based on their schema. |
This skill helps you generate proper GraphQL operations by fetching and analyzing schemas from Apollo GraphOS using the Rover CLI.
Use this skill when the user wants to:
- Generate GraphQL queries, mutations, or subscriptions
- Create reusable GraphQL fragments
- Write operations based on their actual schema
- Understand what fields and types are available
- Build properly typed operations with correct arguments
- Get suggestions for related fields to include
- Validate operation syntax against their schema
This skill combines Rover's schema fetching capabilities with GraphQL operation generation to ensure type-safe, schema-compliant operations.
Workflow:
- Fetch the current schema from GraphOS using Rover
- Parse the schema to understand available types, fields, and arguments
- Generate operations based on the user's natural language description
- Validate the operation against the schema
- Suggest improvements and best practices
Before generating operations, fetch the schema from GraphOS:
# Fetch to stdout
rover graph fetch my-graph@production
# Save to file for analysis
rover graph fetch my-graph@production --output schema.graphql# Fetch subgraph schema
rover subgraph fetch my-graph@production --name products
# Save to file
rover subgraph fetch my-graph@production --name products --output products-schema.graphqlTo avoid repeated fetches:
- Save schema to a local file (e.g.,
schema.graphql) - Reuse the cached schema for operation generation
- Refresh when the user indicates schema has changed
- Store in
.claude/cache/or project root
After fetching, analyze the SDL to identify:
Type Definitions:
- Object types
- Input types
- Enum types
- Interface types
- Union types
- Scalar types
Root Types:
Query- Available read operationsMutation- Available write operationsSubscription- Available real-time operations
Field Information:
- Field names and types
- Required vs optional fields
- Arguments (required/optional, types)
- Nullability
- Lists vs single values
Create GraphQL operations based on user requests:
User request: "Fetch all products with their name, price, and category"
Analyze schema:
type Query {
products: [Product!]!
}
type Product {
id: ID!
name: String!
price: Float!
category: Category!
description: String
inStock: Boolean!
}
type Category {
id: ID!
name: String!
}Generated operation:
query GetProducts {
products {
id
name
price
category {
id
name
}
}
}User request: "Create a mutation to update a product's price"
Analyze schema:
type Mutation {
updateProduct(id: ID!, input: UpdateProductInput!): Product!
}
input UpdateProductInput {
name: String
price: Float
description: String
}Generated operation:
mutation UpdateProductPrice($productId: ID!, $newPrice: Float!) {
updateProduct(id: $productId, input: { price: $newPrice }) {
id
name
price
category {
id
name
}
}
}User request: "Subscribe to new product updates"
Analyze schema:
type Subscription {
productUpdated(categoryId: ID): Product!
}Generated operation:
subscription OnProductUpdated($categoryId: ID) {
productUpdated(categoryId: $categoryId) {
id
name
price
inStock
category {
id
name
}
}
}User request: "Create a reusable fragment for product details"
Generated operation:
fragment ProductDetails on Product {
id
name
price
description
inStock
category {
id
name
}
}
# Usage in query
query GetProducts {
products {
...ProductDetails
}
}When generating operations, follow these guidelines:
query GetProducts {
products {
id # Always include ID for caching
name
price
}
}# Good
query GetProductById($id: ID!) {
product(id: $id) {
id
name
}
}
# Avoid
query {
product(id: "123") {
name
}
}# Good
mutation UpdateProduct($id: ID!, $input: UpdateProductInput!) {
updateProduct(id: $id, input: $input) {
id
name
}
}
# Avoid
mutation {
updateProduct(id: "123", input: { name: "New Name" }) {
id
name
}
}Suggest fields that are commonly needed:
- IDs for caching and references
- Display fields (name, title, etc.)
- Related objects that provide context
- Timestamps (createdAt, updatedAt)
query GetProduct($id: ID!) {
product(id: $id) {
id
name
category {
id
name
# Include category fields users likely need
}
reviews {
id
rating
comment
author {
id
name
# Don't nest too deeply unless requested
}
}
}
}Validate generated operations against the schema:
Check for:
- Field existence on types
- Correct argument names and types
- Required arguments are provided
- Proper nesting of selections
- Valid variable types
- Fragment type conditions match
Common Issues:
❌ Field doesn't exist:
query {
products {
id
cost # Should be 'price'
}
}❌ Missing required argument:
query {
product { # Missing required 'id' argument
id
name
}
}❌ Wrong variable type:
mutation UpdateProduct($id: String!) { # Should be ID!
updateProduct(id: $id, input: { name: "New" }) {
id
}
}query GetProductsWithPagination($limit: Int!, $offset: Int!) {
products(limit: $limit, offset: $offset) {
id
name
price
}
productsCount
}query GetProductsByCategory($categoryId: ID!, $inStock: Boolean) {
products(categoryId: $categoryId, inStock: $inStock) {
id
name
price
inStock
}
}query GetProductsSorted($sortBy: ProductSortField!, $order: SortOrder!) {
products(sortBy: $sortBy, order: $order) {
id
name
price
}
}query GetItems {
items {
id
... on Product {
name
price
}
... on Service {
name
duration
}
}
}query GetMultipleProducts {
product1: product(id: "1") {
id
name
}
product2: product(id: "2") {
id
name
}
}User: "Help me fetch all users with their recent orders"
Steps:
- Fetch schema (if not cached):
rover graph fetch my-graph@production --output schema.graphql- Analyze schema:
type Query {
users: [User!]!
}
type User {
id: ID!
name: String!
email: String!
orders: [Order!]!
}
type Order {
id: ID!
total: Float!
status: OrderStatus!
createdAt: DateTime!
items: [OrderItem!]!
}- Generate operation:
query GetUsersWithRecentOrders {
users {
id
name
email
orders {
id
total
status
createdAt
items {
id
quantity
product {
id
name
price
}
}
}
}
}- Suggest improvements:
- "You might want to limit the number of orders per user"
- "Consider adding pagination for the orders list"
- "Add a filter for order status if you only want recent orders"
- Provide enhanced version:
query GetUsersWithRecentOrders($orderLimit: Int = 5, $orderStatus: [OrderStatus!]) {
users {
id
name
email
orders(limit: $orderLimit, status: $orderStatus, orderBy: CREATED_AT_DESC) {
id
total
status
createdAt
items {
id
quantity
product {
id
name
price
}
}
}
}
}- Start with what the user explicitly requested
- Add essential fields (IDs, names, display fields)
- Suggest related fields that might be useful
- Use variables for dynamic values
- Name operations descriptively
- Include fragments for repeated selections
- Consider pagination for list fields
- Validate against schema before presenting
- Provide usage examples with sample variables
- Suggest error handling fields if available
query GetProductsConnection($first: Int!, $after: String) {
products(first: $first, after: $after) {
edges {
cursor
node {
id
name
price
}
}
pageInfo {
hasNextPage
endCursor
}
}
}query GetProductWithReviews($representations: [_Any!]!) {
_entities(representations: $representations) {
... on Product {
id
name
reviews {
id
rating
comment
}
}
}
}query GetSearchResults($query: String!) {
search(query: $query) {
... on Product {
id
name
price
}
... on Article {
id
title
publishedAt
}
... on User {
id
name
email
}
}
}When schema fetch fails:
- Check authentication (
APOLLO_KEYorrover config auth) - Verify graph ref format (
graph-id@variant) - Confirm graph/subgraph exists in GraphOS
- Check network connectivity
When operation generation is unclear:
- Ask clarifying questions about what data is needed
- Show available types and fields from schema
- Provide examples based on similar patterns
- Offer multiple options if ambiguous
- Use
rover-schemaskill to publish or check schemas - Use
rover-devskill for local testing of operations - Use
rover-supergraphskill for federated schema composition
- GraphQL spec: https://spec.graphql.org/
- Apollo Client operations: https://www.apollographql.com/docs/react/data/queries
- Rover CLI: https://www.apollographql.com/docs/rover
- GraphQL best practices: https://graphql.org/learn/best-practices