Skip to content

Commit

Permalink
Custom document transforms (#10509)
Browse files Browse the repository at this point in the history
Co-authored-by: Lenz Weber-Tronic <lorenz.weber-tronic@apollographql.com>
Co-authored-by: Ben Newman <ben@apollographql.com>
  • Loading branch information
3 people authored May 26, 2023
1 parent ea77bae commit 79df2c7
Show file tree
Hide file tree
Showing 25 changed files with 3,762 additions and 235 deletions.
20 changes: 20 additions & 0 deletions .changeset/warm-pandas-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@apollo/client': minor
---

Add the ability to specify custom GraphQL document transforms. These transforms are run before reading data from the cache, before local state is resolved, and before the query document is sent through the link chain.

To register a custom document transform, create a transform using the `DocumentTransform` class and pass it to the `documentTransform` option on `ApolloClient`.

```ts
import { DocumentTransform } from '@apollo/client';

const documentTransform = new DocumentTransform((document) => {
// do something with `document`
return transformedDocument;
});

const client = new ApolloClient({ documentTransform: documentTransform });
```

For additional documentation on the behavior and API of `DocumentTransform`, see the [pull request](https://github.com/apollographql/apollo-client/pull/10509).
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# format "ObservableQuery" test (in #10597)
104bf11765b1db50292f9656aa8fe48e2d749a83

# format changes from ee0b4ae
f7890ae96a3ba900d3de9bf8b23254bcfba18a25
18 changes: 16 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*.md

# Do not format anything automatically except files listed below
/*
*

##### PATHS TO BE FORMATTED #####
!src/
Expand All @@ -38,9 +38,15 @@ src/react/context/__tests__/*
# Allow src/react/cache
!src/react/cache/

# Allow certain core tests
# Allow certain core files
!src/core
src/core/*
!src/core/__tests__/
src/core/tests/*
!src/core/__tests__/equalByQuery.ts
!src/core/__tests__/DocumentTransform.ts
!src/core/equalByQuery.ts
!src/core/DocumentTransform.ts

# Allowed utilities
!src/utilities/
Expand All @@ -59,6 +65,9 @@ src/utilities/common/*
src/utilities/common/__tests__/*
!src/utilities/common/__tests__/omitDeep.ts
!src/utilities/common/__tests__/stripTypename.ts
!src/utilities/graphql
src/utilities/graphql/*
!src/utilities/graphql/operations.ts

# Allowed links
!src/link
Expand All @@ -78,3 +87,8 @@ src/react/hooks/*
src/react/hooks/__tests__/*
!src/react/hooks/__tests__/useSuspenseQuery.test.tsx
!src/react/hooks/__tests__/useBackgroundQuery.test.tsx

## Allowed testing utils
!src/testing
src/testing/*
!src/testing/matchers
4 changes: 2 additions & 2 deletions .size-limit.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const checks = [
{
path: "dist/apollo-client.min.cjs",
limit: "36.87kb"
limit: "37.06kb"
},
{
path: "dist/main.cjs",
Expand All @@ -10,7 +10,7 @@ const checks = [
{
path: "dist/index.js",
import: "{ ApolloClient, InMemoryCache, HttpLink }",
limit: "35.02kb"
limit: "35.31kb"
},
...[
"ApolloProvider",
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Array [
"ApolloLink",
"ApolloProvider",
"Cache",
"DocumentTransform",
"DocumentType",
"HttpLink",
"InMemoryCache",
Expand Down Expand Up @@ -93,6 +94,7 @@ Array [
"ApolloError",
"ApolloLink",
"Cache",
"DocumentTransform",
"HttpLink",
"InMemoryCache",
"MissingFieldError",
Expand Down Expand Up @@ -421,15 +423,18 @@ Array [
"isExecutionPatchResult",
"isField",
"isInlineFragment",
"isMutationOperation",
"isNodeReadableStream",
"isNodeResponse",
"isNonEmptyArray",
"isNonNullObject",
"isPlainObject",
"isQueryOperation",
"isReadableStream",
"isReference",
"isStatefulPromise",
"isStreamableBlob",
"isSubscriptionOperation",
"iterateObserversSafely",
"makeReference",
"makeUniqueId",
Expand Down
Loading

0 comments on commit 79df2c7

Please sign in to comment.