Helpful extensions to the apollo-ios package.

What's New



What's Changed

  • Update MockApolloClient for API changes in Apollo-iOS 1.9.1
  • Update CI action by @bdbergeron in #3

Full Changelog: 1.0.0...1.1.0


Helpful extensions to the apollo-ios package.

Build and Test codecov CodeFactor


ApolloClientProtocol Default Values

It's wonderful we're provided with ApolloClientProtocol, which ApolloClient conforms to. However, the ApolloClient implementation provides default parameter values that ApolloClientProtocol doesn't provide. Consider this a non-issue now!


Want to test your app's code around ApolloClient? Look no further than MockApolloClient! This mock object conforms to AppoloClientProtocol and allows you to stub responses to queries, mutations, and subscriptions.

func test_query() throws {
  let apolloClient = MockApolloClient()
  apolloClient.fetchResult = { parameters in
    let data = TestQuery.Data(items: .init(edges: [
      .init(node: .init(id: "1",name: "Brad")),
    return .success(GraphQLResult(data: data))

  let expectation = expectation(description: #function)
  apolloClient.fetch(query: TestQuery()) { result in
    switch result {
    case .success(let result):
      XCTAssertEqual(result.data?.items.edges.count, 1)
      XCTAssertEqual(result.data?.items.edges[0].node.id, "1")
      XCTAssertEqual(result.data?.items.edges[0].node.name, "Brad")
    case .failure(let error):
      XCTFail("Unexpected error: \(error)")
  wait(for: [expectation], timeout: 1.0)

Testing / Mocking GraphQLResult

Want to test your generated GraphQL data models against stable JSON data that you control? GraphQLResult.mockedJSONResponse is your answer!

Mock your response, like items.json in your app bundle:

  "data": {
    "items": {
      "__typename": "ItemCollection",
      "edges": [
          "__typename": "ItemCollectionEdge",
          "node": {
            "__typename": "Item",
            "id": "1",
            "name": "Brad"

Then test against that mock response:

func test_mockedJSONResponse() throws {
  let url = try XCTUnwrap(Bundle.module.url(forResource: "items", withExtension: "json"))
  let response = try GraphQLResult.mockedJSONResponse(
    for: TestQuery(),
    jsonURL: url)
  let data = try XCTUnwrap(response.data)
  XCTAssertEqual(data.items.edges.first?.node.__typename, "Item")
  XCTAssertEqual(data.items.edges.first?.node.id, "1")
  XCTAssertEqual(data.items.edges.first?.node.name, "Brad")


  • Swift Tools 5.7.0
View More Packages from this Author


Last updated: Sun Apr 14 2024 21:25:59 GMT-0900 (Hawaii-Aleutian Daylight Time)