Skip to main content
rule

apollo-graphql — Cursor rule: Apollo GraphQL, schema first

A Cursor rule that puts the GraphQL schema before the resolvers in Apollo projects. Useful when your codebase is JavaScript or JSX.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/apollo-graphql.mdc
Open on GitHub

What apollo-graphql does

The rule covers Apollo GraphQL on both sides: Apollo Server 5 on the backend and Apollo Client on the frontend. It starts with the schema, treating it as the contract, and asks you to design and document it before writing implementation code. The examples contrast an implicit schema inferred from resolvers with an explicit SDL type in a file like schema/user.graphql.

It attaches through globs: **/*.{js,jsx}, so it fires on JavaScript and JSX files. A TypeScript or Vue codebase won't match that mask — worth checking before you expect the rule to kick in.

From the opening section, the guide goes on to schema organisation and resolver work. Later sections aren't part of this text, so don't count on specific advice about caching or client hooks up front.

What it helps with

  • design a GraphQL schema before writing resolvers
  • declare types and queries in SDL in a separate file
  • keep one schema structure across a team
  • tell an inferred schema apart from an explicit one
  • document fields and queries inside the schema

Example prompts for the agent

  • Help me design a schema for a new Apollo GraphQL module
  • Split the current resolvers into an SDL schema and the implementation
  • Check schema/user.graphql against the apollo-graphql rules

How to install apollo-graphql

Manually: put the files in place

.cursor/rules/apollo-graphql.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about apollo-graphql

How do I install apollo-graphql in Cursor?

Create .cursor/rules/apollo-graphql.mdc in your project and paste the rule contents into it.

What does the apollo-graphql rule do?

It sets the order of work in Apollo GraphQL: the SDL schema comes first, resolvers after. It covers Apollo Server 5 on the server and Apollo Client on the client.

Which files does the rule apply to?

The mask **/*.{js,jsx} — JavaScript and JSX only. TypeScript files fall outside it.

Source text

apollo-graphql.mdc · CC0-1.0
---
description: Definitive guidelines for building robust, performant, and maintainable apollo-graphql applications using modern best practices and tooling.
globs: **/*.{js,jsx}
---
# apollo-graphql Best Practices

This guide outlines our definitive best practices for developing with Apollo GraphQL, covering both server-side (Apollo Server 5) and client-side (Apollo Client) implementations. Adhering to these rules ensures consistency, performance, and maintainability across our GraphQL ecosystem.

## 1. Schema Design and Organization

Your GraphQL schema is the contract. Design it meticulously, document it thoroughly, and organize it logically.

### 1.1 Schema-First Development with SDL

Always start by defining your schema using Schema Definition Language (SDL). This forces clear API design before implementation.

❌ BAD
```javascript
// Implicit schema definition through resolvers
const resolvers = {
  Query: {
    users: () => [{ id: '1', name: 'Alice' }],
  },
};
// Schema is inferred or built programmatically, harder to review
```

✅ GOOD
```graphql
# schema/user.graphql
"""Represents a user in the system."""
type User {
  id: ID!
  name: String!
  email: String
}

type Query {
  """Fetches a list of all users."""
  users: [User!]!
  """Fetches a single user by their ID."""
  user(id: ID

© sanjeed5 · CC0-1.0 · sanjeed5/awesome-cursor-rules-mdc

Similar IDE rules

All IDE rules for Backend and APIs →

From the same set69

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor