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

MockedProvider seems not supported fragments #12256

Closed
kkh975 opened this issue Jan 8, 2025 · 4 comments
Closed

MockedProvider seems not supported fragments #12256

kkh975 opened this issue Jan 8, 2025 · 4 comments
Labels
🏓 awaiting-contributor-response requires input from a contributor

Comments

@kkh975
Copy link

kkh975 commented Jan 8, 2025

Issue Description

Here is my test Code.

<MockedProvider mocks={[
  {
    request: {
      query: TEST_ANSWER,
      variables: {
        id: 's_901ea6cabd2a729',
      },
    },
    result: {
      data: {
        resp: {
          id: 's_901ea6cabd2a729',
          messages: [
            {
              type: 'TEXT',
              text: 'lorem....',
            },
            {
              type: 'Picture',
              path: 'https://...'
            },
          ],
        },
      },
    },
  },
]} addTypename={false}>
  <TempComp />
</MockedProvider>

and Gql Code.

query GetGraphQAnswer($id: String) {
  resp(id: $id) {
    id
    messages {
      ... on TextMessage {
        type
        text
      }
      ... on PictureMessage {
        type
        path
      }
    }
  }
}

but messages item is empty like below:

[ {}, {} ]

Link to Reproduction

none

Reproduction Steps

No response

@apollo/client version

3.12.4

Copy link

triagster bot commented Jan 8, 2025

Related issues:

Was this useful? Use the thumbs up or thumbs down reaction to give feedback.

@phryneas
Copy link
Member

phryneas commented Jan 8, 2025

You need to add __typename fields to your mocked response and enable addTypename - without knowing if your response is a TextMessage or PictureMessage, these fragments will not be applied to the cache, since they only apply for those types.

@jerelmiller jerelmiller added the 🏓 awaiting-contributor-response requires input from a contributor label Jan 8, 2025
@kkh975
Copy link
Author

kkh975 commented Jan 9, 2025

@phryneas thanks!

@kkh975 kkh975 closed this as completed Jan 9, 2025
Copy link
Contributor

github-actions bot commented Jan 9, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏓 awaiting-contributor-response requires input from a contributor
Projects
None yet
Development

No branches or pull requests

3 participants