Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useFragment invalid return value in the case of null or undefined id in the from argument #11600

Open
kouak opened this issue Feb 15, 2024 · 1 comment

Comments

@kouak
Copy link

kouak commented Feb 15, 2024

Issue Description

When using useFragment, I'm expecting some sort of error or warning if I try to read an object with a null or undefined id.

useFragment<TData>({
  from: {
    __typename: 'Mail',
    id: null,
  },
  fragment,
  fragmentName: 'MyFragment',
});

// v3.8.8:  { complete: false, data: {}, missing: 'Dangling reference to missing Mail:null }
// v3.8.9: { complete: true, data: {} }

This also does not match the typescript return type of useFragment<TData>(); . When complete is true, data should be of type TData.

A workaround is to pass an empty string or false as id.

Link to Reproduction

https://codesandbox.io/p/devbox/recursing-tesla-4f6vt3

Reproduction Steps

Click on the Lookup a person by ID with an empty input.

This will pass null as from.id to useFragment.

@apollo/client version

3.8.9 and later

@kouak kouak changed the title useFragment invalid return value in the case of null or undefined id in the from argument useFragment invalid return value when the store object does not exist Feb 15, 2024
@kouak kouak changed the title useFragment invalid return value when the store object does not exist useFragment invalid return value in the case of null or undefined id in the from argument Feb 15, 2024
@phryneas
Copy link
Member

That looks like a bug, thank you for the report and the reproduction!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants