Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apollo Inline fragment doesn't return data

I'm using Appolo and React Native to query some data. I need to get the isRestriced field from the response by using inline fragments. For every query, I only get userId without the isRestricted field.

I tried various things but couldn't figure out what's causing the issue. Not sure if the problem is with the inline fragment, but this code works in React, but in React-Native, I can't get any data except the userId.

Query:

export const GET_USER = gql`
  query getUser {
    loggedInUser {
      userId
      ... on MainOrganization {
        isUploadEnabled
        organization {
          isRestricted
        }
      }
    }
`;`

Response

userId: "123-456-789-123-42ade233"
__typename: "User"

package.json

"@apollo/client": "^3.3.12",
"react-native": "0.63.4",
"graphql": "^15.5.0",
"graphql-tag": "^2.10.3",
like image 932
J.range Avatar asked Oct 27 '25 22:10

J.range


1 Answers

Did you define a possibleTypes option in your initialization for the InMemoryCache?

see: https://www.apollographql.com/docs/react/data/fragments#using-fragments-with-unions-and-interfaces

It could be that your client is not able to match the fragments. There are some libraries for fragment-matching out there. (f.e. https://www.graphql-code-generator.com/)

like image 73
C. Meier Avatar answered Oct 29 '25 15:10

C. Meier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!