Giter Site home page Giter Site logo

Comments (8)

joelmbell avatar joelmbell commented on August 26, 2024

We're still encountering this issue on the latest build (2.6.24)

Here is some additional information we've encountered while testing.

It seems to only happen after a different query with the cache policy (fetchIgnoringCacheData) has already completed.

Our use-case is that when a user-logs in, a query is performed (fetchIgnoringCacheData) that loads in data that the user will need. This is successful. Once that query is completed, we do a different query fetching some additional information the user needs. For this second query we use the cache policy (returnCacheDataElseFetch). This second query is the one that encounters the issue. No network request is made, and a value from the cache is returned with nil.

We have verified there are no cached values for this query when nil is returned from the cache.
We have verified that if we do not do the first query, then the second one works as expected.

from aws-mobile-appsync-sdk-ios.

peteslavich avatar peteslavich commented on August 26, 2024

We created two tests inside ApolloTests/FetchQueryTests that I believe reproduce the issue. The first test, testSICSecondQueryAlone(), runs successfully, and is essentially a duplicate of testFetchIgnoringCacheData() but uses a StarshipQuery and a .returnCacheDataElseFetch cache policy. The second test, testSICFetchIgnoringCacheData(), first performs the fetch from testFetchIgnoringCacheData(), then in the completion handler of the first query performs the fetch from testSICSecondQueryAlone(). In this case the StarshipQuery returns nil.

func testSICSecondQueryAlone() {
    let query2 = StarshipQuery()
    let initialRecords: RecordSet = [:]
    
    withCache(initialRecords: initialRecords) { cache in
        let store = ApolloStore(cache: cache)
        
        let networkTransport2 = MockNetworkTransport(body: [
            "data": [
                "starship": [
                    "name": "ASDF",
                    "__typename": "Starship"
                ]
            ]
            ])
        let client2 = ApolloClient(networkTransport: networkTransport2, store: store)
        
        let expectation = self.expectation(description: "Fetching query")
        
        client2.fetch(query: query2, cachePolicy: .returnCacheDataElseFetch) { (result, error) in
            defer { expectation.fulfill() }
            
            guard let result = result else { XCTFail("No query result");  return
            }
            guard let name = result.data?.starship?.name else {
                XCTFail("No query result")
                return
            }
            
            XCTAssertEqual(name, "ASDF")
        }
        
        self.waitForExpectations(timeout: 5, handler: nil)
    }
}

func testSICFetchIgnoringCacheData() throws {
    let query = HeroNameQuery()
    
    let initialRecords: RecordSet = [:]
    
    
    withCache(initialRecords: initialRecords) { cache in
        let store = ApolloStore(cache: cache)
        
        let networkTransport = MockNetworkTransport(body: [
            "data": [
                "hero": [
                    "name": "Luke Skywalker",
                    "__typename": "Human"
                ]
            ]
            ])
        
        let client = ApolloClient(networkTransport: networkTransport, store: store)
        
        let expectation = self.expectation(description: "Fetching query")
        let expectation2 = self.expectation(description: "Fetching query2")

        client.fetch(query: query, cachePolicy: .fetchIgnoringCacheData) { (result, error) in
            defer { expectation.fulfill() }
            
            guard let result = result else { XCTFail("No query result");  return }
            
            XCTAssertEqual(result.data?.hero?.name, "Luke Skywalker")
            let query2 = StarshipQuery()
            let networkTransport2 = MockNetworkTransport(body: [
                "data": [
                    "starship": [
                        "name": "ASDF",
                        "__typename": "Starship"
                    ]
                ]
                ])
            let client2 = ApolloClient(networkTransport: networkTransport2, store: store)
            
            client2.fetch(query: query2, cachePolicy: .returnCacheDataElseFetch)
            { (result, error) in
                defer { expectation2.fulfill() }
                
                guard let result = result else { XCTFail("No query result");  return }
                
                guard let name = result.data?.starship?.name else {
                     XCTFail("No query result")
                    return
                }
                
                XCTAssertEqual(name, "ASDF")
            }
        }
        
        self.waitForExpectations(timeout: 5, handler: nil)
    }
}

from aws-mobile-appsync-sdk-ios.

peteslavich avatar peteslavich commented on August 26, 2024

Additionally, we believe the code change that is causing the issue is in commit c417b11 in GraphQLExecutor line 214. In previous versions of app sync that do not show the bug, the second query executes the throw JSONDecodingError.missingValue, while since this change, the second query executes self.complete(...)

from aws-mobile-appsync-sdk-ios.

joelmbell avatar joelmbell commented on August 26, 2024

Thank you @peteslavich!

@rohandubal @palpatim would you like us to submit a pull-request with this test breaking? @peteslavich has narrowed down what looks like the likely cause, but we don't yet fully understand the reason for that change so we are hesitant to change it ourselves.

from aws-mobile-appsync-sdk-ios.

palpatim avatar palpatim commented on August 26, 2024

Hi @joelmbell,

Sorry for the delayed response on this. I have a test that demonstrates this behavior and am investigating the proper way to handle this. I'll update this thread as soon as I have more info.

from aws-mobile-appsync-sdk-ios.

palpatim avatar palpatim commented on August 26, 2024

I was able to make some headway on this during investigations into updating the cache on optimistic updates. PR #182 should fix this, assuming that the approach works as I expect. (I'm investigating whether it is in fact the right approach; I need to validate the assumptions I'm making testing for "empty result values" in that PR.)

from aws-mobile-appsync-sdk-ios.

palpatim avatar palpatim commented on August 26, 2024

This fix is released in 2.10.1. Please let us know if you continue to see issues.

from aws-mobile-appsync-sdk-ios.

stale avatar stale commented on August 26, 2024

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

from aws-mobile-appsync-sdk-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.