-
Notifications
You must be signed in to change notification settings - Fork 446
/
.cursorrules
104 lines (91 loc) · 5.7 KB
/
.cursorrules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# 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"