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

PossibleTypes not working as intended #11878

Closed
Gowthaman-Opti-Twin opened this issue Jun 6, 2024 · 5 comments
Closed

PossibleTypes not working as intended #11878

Gowthaman-Opti-Twin opened this issue Jun 6, 2024 · 5 comments
Labels
🏓 awaiting-contributor-response requires input from a contributor

Comments

@Gowthaman-Opti-Twin
Copy link

I have a query that uses union types inside it.

sample query

person {
      ... on jedi{
        id
        lightsaber
      }
      ... on mandalorian{
        id
        beskar
      }
    }

when I try to use useQuery from apolloClient it is returning the person object with empty brackets [{},{}] but when using fetch() it is returning [{id:232, lightsaber:green},{id:242, beskar: old}]

I tried specifying the union type in the apollo client

const client = new ApolloClient({
  link: concat(authMiddleware, httpLink),
  cache: new InMemoryCache({
    addTypename: false,
    possibleTypes:{Person:['jedi','mandalorian']}
  }),
})

it is not returning the any properties inside the object just an empty object {}

here is the useQuery

const {data:QueryData} = useQuery<PersonQuery>(GET_PERSON)

@dylanwulf
Copy link
Contributor

addTypename: false,

This part is likely your problem. Apollo client needs to have the __typename field available for this functionality to work correctly

@alessbell
Copy link
Contributor

Yes, thanks @dylanwulf!

@Gowthaman-Opti-Twin can you confirm this solved your issue?

@alessbell alessbell added the 🏓 awaiting-contributor-response requires input from a contributor label Jun 7, 2024
@Gowthaman-Opti-Twin
Copy link
Author

Yep, that's the issue. It is working fine now. Thanks

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🏓 awaiting-contributor-response requires input from a contributor
Projects
None yet
Development

No branches or pull requests

3 participants