You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: plugins/wpgraphql-logging/README.md
+55-15Lines changed: 55 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,11 @@ A WPGraphQL logging plugin that provides visibility into request lifecycle to he
6
6
*[Documentation](#getting-started)
7
7
8
8
> [!CAUTION]
9
-
> This plugin is currently in development state and is not production ready.
9
+
> This plugin is currently in alpha state and is not production ready but please feel free to test.
10
10
11
11
-----
12
12
13
-
@TODO - Badges
13
+
@TODO
14
14
15
15
-----
16
16
@@ -19,8 +19,9 @@ A WPGraphQL logging plugin that provides visibility into request lifecycle to he
19
19
## Table of Contents
20
20
21
21
-[Overview](#overview)
22
-
-[Features](#features)
23
22
-[Getting Started](#getting-started)
23
+
-[Features](#features)
24
+
-[Usage](#usage)
24
25
-[Configuration](#configuration)
25
26
-[Extending the Functionality](#extending-the-functionality)
26
27
-[Testing](#testing)
@@ -37,14 +38,16 @@ Designed with extensibility in mind, developers can easily customize and extend
37
38
38
39
---
39
40
40
-
## Features
41
41
42
-
@TODO
42
+
## Getting Started
43
43
44
+
To install, you need to follow our guide here to install the plugin via composer - [https://github.com/wpengine/hwptoolkit/blob/main/docs/how-to/install-toolkit-plugins/index.md]
44
45
45
-
## Getting Started
46
+
Once you have the composer repository setup, please run `composer req wpengine/wpgraphql-logging:*` to install the plugin.
46
47
47
-
@TODO
48
+
Plugin should start logging data, once activated.
49
+
50
+
@TODO add more info once we have configuration setup.
48
51
49
52
50
53
---
@@ -53,10 +56,10 @@ Designed with extensibility in mind, developers can easily customize and extend
-**Before Execution** (`graphql_before_execute`): includes a snapshot of request `params`.
81
+
-**After Execution** (`graphql_execute`): captures `response`/`ExecutionResult`, `schema`, and `request`.
82
+
-**Before Response Returned** (`graphql_return_response`): inspects `response` and automatically upgrades level to Error when GraphQL `errors` are present (adds `errors` to context when found).
77
83
78
-
### Settings
84
+
-**Built-in pub/sub event bus**
85
+
- In-memory event manager with priorities: `subscribe(event, listener, priority)` and `publish(event, payload)`.
86
+
- Transform pipeline: `transform(event, payload)` lets you mutate `context` and `level` before logging/publishing.
87
+
- WordPress bridges: actions `wpgraphql_logging_event_{event}` and filters `wpgraphql_logging_filter_{event}` to integrate with standard hooks.
88
+
89
+
-**Monolog-powered logging pipeline**
90
+
- Default handler: stores logs in a WordPress table (`{$wpdb->prefix}wpgraphql_logging`).
91
+
- Default processors: Memory usage, memory peak, web request, process ID, and `WPGraphQLQueryProcessor` (adds `wpgraphql_query`, `wpgraphql_operation_name`, `wpgraphql_variables`).
92
+
93
+
-**Simple developer API**
94
+
-`Plugin::on()` to subscribe, `Plugin::emit()` to publish, `Plugin::transform()` to modify payloads.
95
+
96
+
-**Safe-by-default listeners/transforms**
97
+
- Exceptions in listeners/transforms are caught and logged without breaking the pipeline.
98
+
99
+
---
100
+
101
+
## Usage
102
+
103
+
WPGraphQL Logging Plugin is highly configurable and extendable and built with developers in mind to allow them to modify, change or add data, loggers etc to this plugin. Please read the docs below:
104
+
105
+
106
+
The following documentation is available in the `docs/` directory:
107
+
108
+
-[Events](docs/Events.md):
109
+
Learn about the event system, available events, and how to subscribe, transform, or listen to WPGraphQL Logging events.
110
+
111
+
-[Logging](docs/Logging.md):
112
+
Learn about the logging system, Monolog integration, handlers, processors, and how to use or extend the logger.
113
+
114
+
---
115
+
116
+
117
+
118
+
## Configuration
79
119
80
120
@TODO - When we integrate plugin configuration.
81
121
82
122
---
83
123
84
-
##Actions & Filters
124
+
### Settings
85
125
86
-
See the [Actions & Filters documentation](ACTIONS_AND_FILTERS.md) for a comprehensive list of available hooks and how to use them.
-[Example 1: How to subscribe to an event](#example-1-how-to-subscribe-to-an-event)
9
+
-[Example 2: How to add context to an event](#example-2-how-to-add-context-to-an-event)
10
+
-[Example 3: How to run a WPGraphQL event](#example-3-how-to-run-a-wpgraphql-event)
11
+
-[Example 4: Use WordPress hooks](#example-4-use-wordpress-hooks)
12
+
13
+
## Overview
14
+
15
+
WPGraphQL Logging implements a pub/sub pattern for events to subscribe to certain WPGraphQL events and allows users to subscribe/publish or transform events.
16
+
17
+
This is achieved in the following classes under `src/Events/`:
18
+
19
+
-**Events** - List of events the plugin hooks into for WPGraphQL
20
+
-**EventManager** - An event manager which creates a pub/sub pattern to allow users to subscribe/publish events and also transform context or level for the current event
21
+
-**QueryEventLifecycle** - The service that puts this all together and creates the logic and logs the data into the LoggerService (Monolog logger)
22
+
23
+
> **Note**: If we are missing anything from this event system, please feel free to create an issue or contribute.
24
+
25
+
## Available Events
26
+
27
+
Currently we subscribe to the following WPGraphQL events:
28
+
29
+
| Event Constant | WPGraphQL Hook | Description |
30
+
| --- | --- | --- |
31
+
|`Events::PRE_REQUEST`|`do_graphql_request`| Before the request is processed |
32
+
|`Events::BEFORE_GRAPHQL_EXECUTION`|`graphql_before_execute`| Before query execution |
33
+
|`Events::AFTER_GRAPHQL_EXECUTION`|`graphql_execute`| After query execution |
34
+
|`Events::BEFORE_RESPONSE_RETURNED`|`graphql_return_response`| Before response is returned to client |
35
+
36
+
## Usage
37
+
38
+
### Example 1: How to subscribe to an event
39
+
40
+
**Use case** You would like to access data for a specific event.
**Use case:** The current list of events that the plugin subscribes too does not give enough information or you need to subscribe to a particular event which is problematic.
88
+
89
+
**Example**
90
+
91
+
Currently the plugin logs at four points in the WPGraphQL lifecycle: `do_graphql_request`, `graphql_before_execute`, `graphql_execute`, `graphql_return_response`. If you need more visibility you could do the following:
0 commit comments