Skip to content

Failed not read fragment from cache #376

@bekaIva

Description

@bekaIva

I'm trying to read fragment from cache with this code
_graphQLClient.readFragment_ConvergedCartDetailsTest( idFields: {'__typename': 'ConvergedCart', 'ccid': ccid}, );

here is a fragment definition

fragment ConvergedCartDetailsTest on ConvergedCart{
  ccid
  version
  subCarts
  {
    itemGroups {
      items
      {
        price {
          ...priceFragment
        }
      }
    }
  }
}

fragment priceFragment on Price
{
  priceId
  ... on SubsidyPrice {
    payTodayPrice
  }
}

but, it loads incomplete data for the fragment and it fails to parse from json because of required fields missing
Screenshot from 2024-12-16 00-10-59 bad result

priceId and payTodayPrice fields are missing.

although, if I don't insert price query as a fragment then it works.
The fragment:

fragment ConvergedCartDetailsTest on ConvergedCart{
 ccid
 version
 subCarts
 {
   itemGroups {
     items
     {
       price {
         priceId
         ... on SubsidyPrice {
           payTodayPrice
         }
       }
     }
   }
 }
}

In this case I can successfully read the fragment
Screenshot from 2024-12-16 00-00-29 good result

I done some research and these values are lost during the normalization and they are not saved into the cache if I use first fragment where another fragment is used for price field which is an interface type.
Screenshot from 2024-12-16 00-28-05 not saved

this is the schema for Price type

""" Can be subsidy or loan """
interface Price {
    priceId: String!
    payTodayPrice: Float
  #  other fields removed
}

""" Represents a subsidy price """
type SubsidyPrice implements Price {
    priceId: String!
    payTodayPrice: Float
  #  other fields removed
}

""" Represents a loan price """
type LoanPrice implements Price {
    priceId: String!
    payTodayPrice: Float
  #  other fields removed
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions