contentful / contentful.swift

A delightful Swift interface to Contentful's content delivery API.
MIT License
202 stars 82 forks source link

refactor: made `Sys.type` optional to work with GraphQL API #404

Closed TizianoCoroneo closed 1 month ago

TizianoCoroneo commented 4 months ago

I'm working with Contentful's GraphQL API to display our company magazine content natively within our iOS app.

I encountered an issue when decoding Entry links within the body of an article: in the implementation of the library we have a non-optional type field within the Sys object, but in the GraphQL API the Sys type has no such field. Rather, you can find the concrete type of an Entry field by checking the "__typename" field on the Entry itself instead of inside the Sys object.

This PR makes the type field within Sys optional, so that we can still decode an Entry object from the raw JSON payload received via the GraphQL API.

There is also another change: I noticed that we pass the entry.sys.type field value to the Link initializer. This field will contain the name of the concrete entry type, instead of only "Entry" or "Asset" as stated in the documentation comment of the Link.linkType field. I modified the relevant code to pass the string "Entry" instead, in accord with the documentation.

mgoudy91 commented 4 months ago

Thanks for the contribution!

@mariuskatcontentful let me know what you think about this when you have a sec

mariuskatcontentful commented 1 month ago

Look good to me - merged