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

graphql union type extraction fragment doesn't get mapping field values #11588

Closed
krrrr38 opened this issue Feb 11, 2024 · 4 comments
Closed

Comments

@krrrr38
Copy link

krrrr38 commented Feb 11, 2024

Issue Description

When defining union type and getting these fields from fragment, apollo-client doesn't get these values.

Link to Reproduction

krrrr38/react-apollo-error-template#1

Reproduction Steps

See the reproduction PR. In this pr, graphql defines PetData union data.

union PetData = DogData | CatData

type DogData {
  dogData: String!
}

type CatData {
  dogData: String!
}

When accessing data using fragment AllPetData, apollo-client doesn't get dogData and catData.

貼り付けた画像_2024_02_11_22_17
  fragment AllPetData on PetData {
    ... on DogData {
      dogData
    }
    ... on CatData {
      catData
    }
  }
  query AllPeople {
    people {
      id
      name
      pet
      data {
        ...AllPetData
      }
    }
  }

For workaround, we should remove fragment.

  query AllPeople {
    people {
      id
      name
      pet
      data {
        ... on DogData {
          dogData
        }
        ... on CatData {
          catData
        }
      }
    }
  }

@apollo/client version

3.9.4

@phryneas
Copy link
Member

Hi!

Have you made sure to specify possibleTypes in your cache configuration?

@krrrr38
Copy link
Author

krrrr38 commented Feb 12, 2024

wow, it resolves the issue. Thank you so much for the information!

  cache: new InMemoryCache({
    possibleTypes: {
      PetData: ["CatData", "DogData"],
    }
  }),
image

@krrrr38 krrrr38 closed this as completed Feb 12, 2024
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 Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants