Skip to content

Commit

Permalink
Add fragment name to warning
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 14, 2024
1 parent 885be47 commit fd66d42
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/__tests__/dataMasking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,8 @@ test("warns when passing parent object to `from` when id is masked", async () =>

expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenCalledWith(
"Could not identify object passed to `from` either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object."
"Could not identify object passed to `from` for '%s' fragment, either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object.",
"UserFields"
);

const fragmentStream = new ObservableStream(fragmentObservable);
Expand Down Expand Up @@ -1288,7 +1289,8 @@ test("warns when passing parent object to `from` that is non-normalized", async

expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenCalledWith(
"Could not identify object passed to `from` either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object."
"Could not identify object passed to `from` for '%s' fragment, either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object.",
"UserFields"
);

const fragmentStream = new ObservableStream(fragmentObservable);
Expand Down
7 changes: 6 additions & 1 deletion src/cache/core/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Observable,
cacheSizes,
defaultCacheSizes,
getFragmentDefinition,
getFragmentQueryDocument,
mergeDeepArray,
} from "../../utilities/index.js";
Expand Down Expand Up @@ -248,9 +249,13 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
const id = typeof from === "string" ? from : this.identify(from);

if (__DEV__) {
const actuaFragmentName =
fragmentName || getFragmentDefinition(fragment).name.value;

if (!id) {
invariant.warn(
"Could not identify object passed to `from` either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object."
"Could not identify object passed to `from` for '%s' fragment, either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object.",
actuaFragmentName
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/react/hooks/__tests__/useFragment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,8 @@ describe("useFragment", () => {

expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenCalledWith(
"Could not identify object passed to `from` either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object."
"Could not identify object passed to `from` for '%s' fragment, either because the object is non-normalized or the key fields are missing. If you are masking this object, please ensure the key fields are requested by the parent object.",
"UserFields"
);

{
Expand Down

0 comments on commit fd66d42

Please sign in to comment.