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

Update Apollo to 1.0.0 and use via SPM Plugins #51

Merged
merged 2 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ios/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Localizable.strings

## Generated code
*.generated.swift
*.graphql.swift
*.graphqls

## Various settings
*.pbxuser
Expand Down
6 changes: 4 additions & 2 deletions ios/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ excluded:
- Carthage
- Pods
- vendor
- DataLayer/Toolkits/RocketToolkit/Sources/RocketToolkit/NetworkModels/NETModels.generated.swift

- DataLayer/Toolkits/RocketToolkit/.build
- DataLayer/Toolkits/RocketToolkit/Sources/RocketToolkit/NetworkModels/Apollo
- DataLayer/Toolkits/RocketToolkit/Sources/RocketToolkitMocks

indentation: 2
cyclomatic_complexity: 10
file_length: 200
Expand Down
7 changes: 5 additions & 2 deletions ios/DataLayer/Providers/GraphQLProvider/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import PackageDescription

let package = Package(
name: "GraphQLProvider",
platforms: [.iOS(.v14)],
platforms: [
.iOS(.v14),
.macOS(.v10_14)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
Expand All @@ -20,7 +23,7 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/apollographql/apollo-ios", .upToNextMajor(from: "0.0.0"))
.package(url: "https://github.com/apollographql/apollo-ios", .upToNextMajor(from: "1.0.0"))
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//

import Apollo
import ApolloAPI
import Foundation

// Extension which adds async/await support to Apollo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//

import Apollo
import ApolloAPI
import Foundation

public struct ApolloGraphQLProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//

import Apollo
import ApolloAPI
import Foundation

// sourcery: AutoMockable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// swiftlint:disable all

import Apollo
import ApolloAPI
import Foundation
import GraphQLProvider

Expand Down
59 changes: 59 additions & 0 deletions ios/DataLayer/Toolkits/RocketToolkit/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"pins" : [
{
"identity" : "apollo-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apollographql/apollo-ios",
"state" : {
"revision" : "33065d3b3c97fc35ac42bf28f826cac6c61c779e",
"version" : "1.0.0"
}
},
{
"identity" : "inflectorkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattt/InflectorKit",
"state" : {
"revision" : "d8cbcc04972690aaa5fc760a2b9ddb3e9f0decd7",
"version" : "1.0.0"
}
},
{
"identity" : "resolver",
"kind" : "remoteSourceControl",
"location" : "https://github.com/hmlongco/Resolver.git",
"state" : {
"revision" : "97de0b0320036607564af4a60025b48f8d041221",
"version" : "1.5.0"
}
},
{
"identity" : "sqlite.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stephencelis/SQLite.swift.git",
"state" : {
"revision" : "4d543d811ee644fa4cc4bfa0be996b4dd6ba0f54",
"version" : "0.13.3"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "9f39744e025c7d377987f30b03770805dcb0bcd1",
"version" : "1.1.4"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "f504716c27d2e5d4144fa4794b12129301d17729",
"version" : "1.0.3"
}
}
],
"version" : 2
}
22 changes: 17 additions & 5 deletions ios/DataLayer/Toolkits/RocketToolkit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import PackageDescription

let package = Package(
name: "RocketToolkit",
platforms: [.iOS(.v14)],
platforms: [
.iOS(.v14),
.macOS(.v10_14)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
Expand All @@ -16,9 +19,9 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(name: "SharedDomain", path: "../../DomainLayer/SharedDomain"),
.package(name: "GraphQLProvider", path: "../Providers/GraphQLProvider"),
.package(url: "https://github.com/apollographql/apollo-ios", .upToNextMajor(from: "0.0.0"))
.package(name: "SharedDomain", path: "../../../DomainLayer/SharedDomain"),
.package(name: "GraphQLProvider", path: "../../Providers/GraphQLProvider"),
.package(url: "https://github.com/apollographql/apollo-ios", .upToNextMajor(from: "1.0.0"))
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand All @@ -34,14 +37,23 @@ let package = Package(
.process("NetworkQueries")
]
),
.target(
name: "RocketToolkitMocks",
dependencies: [
"RocketToolkit",
.product(name: "ApolloTestSupport", package: "apollo-ios")
]
),
.testTarget(
name: "RocketToolkitTests",
dependencies: [
"RocketToolkit",
"RocketToolkitMocks",
.product(name: "SharedDomain", package: "SharedDomain"),
.product(name: "SharedDomainMocks", package: "SharedDomain"),
.product(name: "GraphQLProvider", package: "GraphQLProvider"),
.product(name: "GraphQLProviderMocks", package: "GraphQLProvider")
.product(name: "GraphQLProviderMocks", package: "GraphQLProvider"),
.product(name: "ApolloTestSupport", package: "apollo-ios")
]
)
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @generated
// This file was automatically generated and can be edited to
// provide custom configuration for a generated GraphQL schema.
//
// Any changes to this file will not be overwritten by future
// code generation execution.

import ApolloAPI

enum SchemaConfiguration: ApolloAPI.SchemaConfiguration {
static func cacheKeyInfo(for type: Object, object: JSONObject) -> CacheKeyInfo? {
// Implement this function to configure cache key resolution for your schema types.
return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@
// Copyright © 2022 Matee. All rights reserved.
//

import ApolloAPI
import SharedDomain

// Conversion from NetworkModel to DomainModel
extension RocketLaunchListQuery.Data.Launch.Launch {
extension Rocket.RocketLaunchListQuery.Data.Launches.Launch {
var domainModel: RocketLaunch {
RocketLaunch(
id: id,
site: site ?? ""
)
}
}

// Conversion from DomainModel to NetworkModel
extension RocketLaunch {
var networkModel: RocketLaunchListQuery.Data.Launch.Launch {
.init(
id: id,
site: site
site: site ?? ""
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public struct RocketLaunchRepositoryImpl: RocketLaunchRepository {
self.graphQL = graphQLProvider
}

public func read() -> AsyncThrowingStream<[RocketLaunch], Error> {
public func list() -> AsyncThrowingStream<[RocketLaunch], Error> {
AsyncThrowingStream { continuation in
Task {
do {
for try await result in graphQL.fetch(query: RocketLaunchListQuery()) {
for try await result in graphQL.fetch(query: Rocket.RocketLaunchListQuery()) {
guard let data = result.data else { return }
continuation.yield(data.launches.launches.compactMap { $0?.domainModel })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
//

import Apollo
import ApolloAPI
import ApolloTestSupport
import GraphQLProvider
import GraphQLProviderMocks
@testable import RocketToolkit
import RocketToolkitMocks
import SharedDomain
import SharedDomainMocks
import XCTest
Expand All @@ -15,22 +18,25 @@ final class RocketLaunchRepositoryTests: XCTestCase {

// MARK: Dependencies

private let graphQLProvider = GraphQLProviderMock<RocketLaunchListQuery>()
private let graphQLProvider = GraphQLProviderMock<Rocket.RocketLaunchListQuery>()

private func createRepository() -> RocketLaunchRepository {
RocketLaunchRepositoryImpl(graphQLProvider: graphQLProvider)
}

// MARK: Tests

func testRead() async throws {
func testList() async throws {
let repository = createRepository()
let rocketLaunches = [RocketLaunch].stub.map { $0.networkModel }
let queryData = RocketLaunchListQuery.Data(launches: .init(cursor: "0", hasMore: true, launches: rocketLaunches))
let queryData = Rocket.RocketLaunchListQuery.Data.from(Mock<Query>(
launches: Mock<LaunchConnection>(
launches: [RocketLaunch].stub.map { Mock<Launch>(id: $0.id, site: $0.site) }
)
))
let queryResult = GraphQLResult(data: queryData, extensions: nil, errors: nil, source: .server, dependentKeys: nil)
graphQLProvider.fetchReturnValues = [queryResult]

let rocketLaunchesStream = repository.read()
let rocketLaunchesStream = repository.list()

for try await rocketLaunches in rocketLaunchesStream {
XCTAssertEqual(rocketLaunches, [RocketLaunch].stub)
Expand Down
44 changes: 44 additions & 0 deletions ios/DataLayer/Toolkits/RocketToolkit/apollo-codegen-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"schemaName": "rocket",
"schemaDownloadConfiguration": {
"downloadMethod": {
"introspection": {
"endpointURL": "https://apollo-fullstack-tutorial.herokuapp.com/graphql",
"httpMethod": {
"POST": {}
},
"includeDeprecatedInputValues": false,
"outputFormat": "SDL"
}
},
"downloadTimeout": 60,
"headers": [],
"outputPath": "./schema.graphqls"
},
"input": {
"operationSearchPaths": [
"./Sources/RocketToolkit/NetworkQueries/*.graphql"
],
"schemaSearchPaths": [
"./schema.graphqls"
]
},
"output": {
"schemaTypes": {
"path": "./Sources/RocketToolkit/NetworkModels/Apollo",
"moduleType": {
"embeddedInTarget": {
"name": "RocketToolkit"
}
}
},
"operations": {
"inSchemaModule": {}
},
"testMocks": {
"absolute": {
"path": "./Sources/RocketToolkitMocks"
}
}
}
}
Loading