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

Failed not read fragment from cache #376

Open
bekaIva opened this issue Dec 15, 2024 · 3 comments
Open

Failed not read fragment from cache #376

bekaIva opened this issue Dec 15, 2024 · 3 comments

Comments

@bekaIva
Copy link

bekaIva commented Dec 15, 2024

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
}
Copy link

👋 @bekaIva
Thank you for raising an issue. I will investigate the issue and get back to you as soon as possible.
Please make sure you have provided enough context.

This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here.

@budde377
Copy link
Contributor

On the face of it, this doesn't sound like an issue with graphql codegen. A simple test would be to see if you are experiencing the same issues by calling the underlying client directly. Unless you find some errors in the generated code, I suspect you will be able to find the same issues.

I don't know how you populate or configure your cache, but that would be my recommendation for you to look at first.

@bekaIva
Copy link
Author

bekaIva commented Dec 15, 2024

that's a only configuration for the cache
image
I'll check querying without the generated method to see if it caches properly in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants