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
This library, primarily through its `transform()` export, provides several helpful functionalities for working with GraphQL results:
26
26
27
-
- Configurable synchronous leaf value transformers, object field transformers, and path-scoped field transformers for modifying GraphQL results.
28
-
- Mapping from the latest incremental delivery format to the legacy format.
27
+
-**Result Composition:** Combine GraphQL results, including incremental delivery payloads (`@defer`/`@stream`), from multiple downstream GraphQL services into a single unified result. (Note: Composition is currently under development and primarily functional for root fields.)
28
+
-**Result Transformation:** Modify results using configurable transformers based on the leaf type, object field, or specific location within a GraphQL operation.
29
+
-**Legacy Incremental Format Mapping:** Convert results from the modern incremental delivery specification to the legacy format used in earlier `graphql-js` versions.
29
30
30
-
Note: In the case of multiple transformers, execution is in the above order: first any leaf value transformer is executed, followed by any object field transformer, and then the path-scoped field transformer.
31
+
Notes:
32
+
33
+
- When multiple transformer types are applied to the same field, they execute in the following order: leaf value transformer -> object field transformer -> path-scoped field transformer.
34
+
35
+
- A separate `legacyExecuteIncrementally()` export is also available. It leverages the same underlying transformation logic but is specifically designed to provide backwards compatibility for the legacy incremental delivery format when interacting with a single GraphQL service (i.e., without composition).
31
36
32
37
## Usage
33
38
34
-
### Configurable Leaf Transformers
39
+
### Composition of GraphQL Results
35
40
36
-
Pass `leafTransformers` in a `Transformers` object to `transformResult()`.
41
+
To compose results from multiple GraphQL services, provide a `subschemas` array to `transform()`:
Pass `objectFieldTransformers` in a `Transformers`object to `transformResult()`, namespaced by type and field.
99
+
To apply transformations to specific fields within object types, pass `objectFieldTransformers`to `transform()`, namespaced by type name and field name:
Pass `pathScopedFieldTransformers` in a `Transformers` object to `transformResult()`, keyed by a period-delimited path to the given field within the operation. (Numeric indices for list fields are simply skipped, reflecting the path within the given operation rather than the result.)
131
+
To apply transformations based on a field's specific location within the operation, pass `pathScopedFieldTransformers`to `transform()`. The keys are period-delimited paths reflecting the field structure in the operation (numeric list indices are omitted).
Convert from the the latest incremental delivery format to the legacy format:
149
+
If you need to interact with systems expecting the older incremental delivery format (from `graphql-js` pre-v17), you can enable conversion:
150
+
151
+
```ts
152
+
import { transform } from'@yaacovCR/transform';
153
+
154
+
const result =awaittransform({
155
+
schema,
156
+
document,
157
+
variableValues,
158
+
subschemas,
159
+
legacyIncremental: true,
160
+
});
161
+
```
162
+
163
+
Alternatively, if you are working with a single GraphQL service (no composition) and need the legacy format, the `legacyExecuteIncrementally()` function provides a dedicated interface:
0 commit comments