Shopify / mobile-buy-sdk-ios

Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using Apple Pay or their credit card.
MIT License
452 stars 199 forks source link

Deprecated Properties Crash after updating to 3.2 #952

Closed natecraft1 closed 5 years ago

natecraft1 commented 5 years ago

Images now have a transformedSrc rather than a src property. We are getting a crash after updating the SDK because we have CartItems stored locally and when we try to deserialize them, their Image models don't match because they contain the old src property. This leads to a crash in GraphQL

screen shot 2018-12-04 at 2 10 17 pm

What is the proper way to introduce new properties without crashing the app? Thanks!

dbart01 commented 5 years ago

I would highly discourage persisting raw GraphQL models / data. I'd recommend migrating to a custom JSON serialization format that doesn't rely on GraphQL field versioning to prevent this in the future. For now, as a workaround, you can request both deprecated and non-deprecated fields to avoid crashing.

natecraft1 commented 5 years ago

@dbart01 Thanks, I took the serialization from the example project's CartController. If possible could you elaborate on how you might persist CartItems without GraphQL models. I guess my confusion is that properties within CartItem contain models which are Storefront models. Maybe it would suffice to just store the ids of the models and fetch them when possible? Anyways would like to know your thoughts, any direction helps.

dbart01 commented 5 years ago

The idea is to abstract GraphQL models behind your own version of CartItem that knows how to serialize and deserialize from a JSON representation. Doing so will allow you to update the GraphQL schema, which may add or remove fields, without affecting the ability to read / write to and from your JSON representation. You can then add default values in your proprietary model for new / missing fields, etc. Hopefully this makes a little more sense.