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

resolveLinksArray returns array of NSNulls #329

Open
2 of 6 tasks
pzmudzinski opened this issue Jan 12, 2021 · 6 comments
Open
2 of 6 tasks

resolveLinksArray returns array of NSNulls #329

pzmudzinski opened this issue Jan 12, 2021 · 6 comments

Comments

@pzmudzinski
Copy link

pzmudzinski commented Jan 12, 2021

  • contentful.swift version number: 5.4.1
  • Xcode version number: 12.3
  • Target operating system(s) and version number(s)
    • iOS:
    • tvOS:
    • watchOS:
    • macOS:
  • Package manager:
    • Carthage
    • Cocoapods

I've got entry with one-to-many array of some other entries. Trying to decode it like that:

try fields.resolveLinksArray(forKey: .possibleAnswers, decoder: decoder) { [weak self] answers in ... }

I've registered both types of entries in contentTypeClasses, I've got the same code working for other entries but for some reason one specific type causes this issue (it's not even reaching constructor) - it shows correct number of entries but all of them are NSNull without any error message or explanation what's going on:
image

What could be causing that? How are we supposed to debug any decoding issues? Why it isn't giving any information what could be an issue?

In addition if I try to fetch one record of that type everything works:

client.fetch(typeOfPossibleAnswers, id: "...") { result in
                print("result \(result)") // success! 
            }
@pzmudzinski
Copy link
Author

pzmudzinski commented Jan 12, 2021

One thing to add is the structure is like that:
there is entity A, which has array of entities B, and each entity B has another array of entities C.
If I fetch entity B - it works and I see it decodes array of entities C.
If I fetch entity A, it decodes entities B but it does not reach to decoding any of C.

Does this SDK not support nested links at depth 2?

@pzmudzinski
Copy link
Author

Ok after digging into the code I think I've found Query.include method which manages "depth" of that fetch.
So solution was to use myQuery.include(3).

I think this is something which should be added to Readme - I couldn't find any info on that and default behavior withNSNulls seems to be weird.

@mariuskurgonas
Copy link
Contributor

Hey @pzmudzinski ,

Thanks you for the feedback and great that in the end you found the solution. I will make sure this is added to the documentation going forwards.

I will also look into why does it return the array of nulls in case the depth level is not specified. I think i generally understood your use case and setup with arrays within arrays. Would you be able to share a simple working example of the code that would help me see the complete picture of your setup and help me in reproducing exactly the way you tried it?

@marius-se
Copy link

marius-se commented Feb 3, 2021

I had the exact same issues. The Query.include really helped me a lot. Thanks @pzmudzinski for pointing that out!

...Interesting: If the key is representing an Asset value, everything works just fine. Is there a reason for that? Let's say I have:

-states: [State]
--facilities: [Facility]
---address: Address
---image: Asset

Without specifying the Query.include the image property will be resolved while the address won't.

@pzmudzinski
Copy link
Author

@marius-se It took me like 5 hours to figure it out so appreciate your comment 😂
@mariuskurgonas nothing fancy, just use Client and do an query for entity with nested arrays, just like in my A-B-C example

@leonardopantaleao
Copy link

leonardopantaleao commented Mar 18, 2022

I hope I can save someone else's time:
EntryType = the class type you're struggling to get the array with arrays
let query = QueryOn<EntryType>.include(3)
client.fetchArray(of: EntryType.self, matching: query) { response in
...

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

4 participants