wp-graphql wp-graphql .cursorrules file for PHP (stars: 3674)

# WPGraphQL is a WordPress plugin that adds a /graphql endpoint to the WordPress site and defines a GraphQL Schema based on internal WordPress registries such as the post type, taxonomy and settings registries. It includes the Schema, resolvers and a model layer for determining access to objects before resolving them. It is extendable by using WordPress hooks and filters via the add_action and add_filter functions. It follows phpcs standards defined in .phpcs.xml.dist. It uses composer to manage external dependencies such as graphql-php. It includes user interfaces in the WordPress admin dashboard for plugin settings and the GraphiQL IDE for interacting with the GraphQL Schema and testing queries and mutations.

## Frameworks and Technologies
- framework: wordpress
- language: php
- package-manager: composer
- testing-framework: phpunit (codeception, wp-graphql-testcase)
- coding-standards: phpcs
- api: graphql

## Key Concepts
- concept: "GraphQL Schema": "The structure that defines the types, queries, and mutations available in the WPGraphQL API"
- concept: "WordPress Registries": "Internal WordPress systems that store information about post types, taxonomies, and settings"
- concept: "Resolvers": "Functions that determine how to fetch and return data for specific GraphQL fields"
- concept: "Model Layer": "Classes that handle access control and data preparation before resolution"
- concept: "GraphiQL IDE": "An interactive development environment for testing GraphQL queries"

## File Patterns
- pattern: "src/Admin/*.php": "WordPress admin interface implementations"
- pattern: "src/Connection/*.php": "Classes handling GraphQL connections and pagination"
- pattern: "src/Data/*.php": "Data manipulation and transformation classes"
- pattern: "src/Model/*.php": "Model classes that handle data access and authorization"
- pattern: "src/Mutation/*.php": "Classes defining GraphQL mutations"
- pattern: "src/Registry/*.php": "Classes for registering types and fields"
- pattern: "src/Server/*.php": "Validation Rules and other configuration for the GraphQL Server"
- pattern: "src/Type/*.php": "GraphQL type definitions"
- pattern: "src/Utils/*.php": "Utility classes and helper functions"
- pattern: "tests/**/*.php": "PHPUnit test files"
- pattern: "access-functions.php": "Global access functions"
- pattern: "docs/*.md": "User documentation for the plugin"
- pattern: "cli/*.php": "WP-CLI commands for interacting with WPGraphQL using WP-CLI"
- pattern: "phpstan/*.php": "Stubs for use with phpstan for static analysis"
- pattern: "packages/**/*.js": "JavaScript packages that make up the GraphiQL IDE"
- pattern: ".wordpress-org/": "Files used for building and deploying the plugin to WordPress.org"

## Dependencies
- dependency: "webonyx/graphql-php": "Core GraphQL PHP implementation"
- dependency: "ivome/graphql-relay-php": "Relay specification implementation"
- dependency: "phpunit/phpunit": "Testing framework"
- dependency: "squizlabs/php_codesniffer": "Code style checking"
- dependency: "phpstan/phpstan": "Static analysis tool"
- dependency: "wp-coding-standards/wpcs": "WordPress Coding Standards"

## Common Code Patterns
```php
// Registering a GraphQL Type
add_action( 'graphql_register_types', function( $type_registry ) {

    register_graphql_object_type( 'TypeName', [
        'fields' => [
            'fieldName' => [
                'type' => 'String',
                'resolve' => function($source, $args, $context, $info) {
                    // Resolution logic
                }
            ]
        ]
    ]);

});

// Registering a GraphQL Field
add_action( 'graphql_register_types', function( $type_registry ) {

    register_graphql_field( 'TypeName', 'FieldName', [
        'description' => __( 'Description of the field', 'your-textdomain' ),
        'type' => 'String',
        'resolve' => function() {
            // interact with the WordPress database, or even an external API or whatever.
            return 'value retrieved from WordPress, or elsewhere';
        }
    ]);

});
```

## Key Directories
- directory: "src/": "Core plugin source code"
- directory: "includes/": "Plugin includes and utilities"
- directory: "tests/": "Test files"
- directory: "docs/": "Documentation"
- directory: "languages/": "Translation files"
- directory: ".github/": "Files used for interacting with GitHub"
- directory ".wordpress-org/": "Files used for building and deploying the plugin to WordPress.org"
- directory "build/": "Contains the built assets for the GraphiQL IDE"
- directory "bin/": "Contains scripts used in CI"
- directory "docker/": "Contains configuration for running WPGraphQL in Docker"
- directory "img": "Contains images used in documentation"
- directory: "phpstan/": "PHPStan configuration and stubs"

## Important Files
- file: "wp-graphql.php": "Main plugin file"
- file: "composer.json": "Dependency management"
- file: ".phpcs.xml.dist": "PHP CodeSniffer configuration"
- file: "phpunit.xml.dist": "PHPUnit configuration"
- file: "access-functions.php": "Global access functions"
- file: "phpstan.neon.dist": "PHPStan configuration"
- file: "docker-compose.yml": "Docker environment configuration"
- file: ".wordpress-org/blueprints/blueprint.json": "Blueprint for running WPGraphQL in WordPress Playground, a WASM environment that runs WordPress fully in the browser"

## Debug Tools
- concept: "GraphQL Debug Mode": "Enable via WPGraphQL Settings or define('GRAPHQL_DEBUG', true)"
- concept: "Query Logs": "Logs the SQL queries to fulfil a graphql request. Requires Query Monitor to be active. Enabled via WPGraphQL Settings and available in GraphiQL when debug mode is enabled"
- concept: "Query Tracing": "Shows trace data for resolvers (i.e. timing for execution). Enabled via WPGraphQL Settings and available in GraphiQL when debug mode is enabled"
docker
dockerfile
graphql
java
javascript
php
scss
shell

First Time Repository

:rocket: GraphQL API for WordPress

PHP

Languages:

Dockerfile: 4.9KB
JavaScript: 171.6KB
PHP: 2553.3KB
SCSS: 5.1KB
Shell: 15.7KB
Created: 10/31/2016
Updated: 1/23/2025

All Repositories (1)

:rocket: GraphQL API for WordPress