Skip to content

Commit 07f1ac2

Browse files
committed
run codegen, add update
1 parent 18b491c commit 07f1ac2

14 files changed

+151
-74
lines changed

Tests/IntegrationTestApp/AppSyncAPI/Sources/Operations/Mutations/CreateTodoMutation.graphql.swift

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
//
2-
// Copyright Amazon.com Inc. or its affiliates.
3-
// All Rights Reserved.
4-
//
5-
// SPDX-License-Identifier: Apache-2.0
6-
//
1+
// @generated
2+
// This file was automatically generated and should not be edited.
73

84
@_exported import ApolloAPI
95

@@ -24,7 +20,7 @@ public class CreateTodoMutation: GraphQLMutation {
2420

2521
public struct Data: AppSyncAPI.SelectionSet {
2622
public let __data: DataDict
27-
public init(_dataDict: DataDict) { self.__data = _dataDict }
23+
public init(_dataDict: DataDict) { __data = _dataDict }
2824

2925
public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Mutation }
3026
public static var __selections: [ApolloAPI.Selection] { [
@@ -38,7 +34,7 @@ public class CreateTodoMutation: GraphQLMutation {
3834
/// Parent Type: `Todo`
3935
public struct CreateTodo: AppSyncAPI.SelectionSet {
4036
public let __data: DataDict
41-
public init(_dataDict: DataDict) { self.__data = _dataDict }
37+
public init(_dataDict: DataDict) { __data = _dataDict }
4238

4339
public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Todo }
4440
public static var __selections: [ApolloAPI.Selection] { [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// @generated
2+
// This file was automatically generated and should not be edited.
3+
4+
@_exported import ApolloAPI
5+
6+
public class UpdateTodoMutation: GraphQLMutation {
7+
public static let operationName: String = "UpdateTodo"
8+
public static let operationDocument: ApolloAPI.OperationDocument = .init(
9+
definition: .init(
10+
#"mutation UpdateTodo($updateTodoInput: UpdateTodoInput!) { updateTodo(input: $updateTodoInput) { __typename id updatedAt createdAt content owner } }"#
11+
))
12+
13+
public var updateTodoInput: UpdateTodoInput
14+
15+
public init(updateTodoInput: UpdateTodoInput) {
16+
self.updateTodoInput = updateTodoInput
17+
}
18+
19+
public var __variables: Variables? { ["updateTodoInput": updateTodoInput] }
20+
21+
public struct Data: AppSyncAPI.SelectionSet {
22+
public let __data: DataDict
23+
public init(_dataDict: DataDict) { __data = _dataDict }
24+
25+
public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Mutation }
26+
public static var __selections: [ApolloAPI.Selection] { [
27+
.field("updateTodo", UpdateTodo?.self, arguments: ["input": .variable("updateTodoInput")]),
28+
] }
29+
30+
public var updateTodo: UpdateTodo? { __data["updateTodo"] }
31+
32+
/// UpdateTodo
33+
///
34+
/// Parent Type: `Todo`
35+
public struct UpdateTodo: AppSyncAPI.SelectionSet {
36+
public let __data: DataDict
37+
public init(_dataDict: DataDict) { __data = _dataDict }
38+
39+
public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Todo }
40+
public static var __selections: [ApolloAPI.Selection] { [
41+
.field("__typename", String.self),
42+
.field("id", AppSyncAPI.ID.self),
43+
.field("updatedAt", AppSyncAPI.AWSDateTime.self),
44+
.field("createdAt", AppSyncAPI.AWSDateTime.self),
45+
.field("content", String?.self),
46+
.field("owner", String?.self),
47+
] }
48+
49+
public var id: AppSyncAPI.ID { __data["id"] }
50+
public var updatedAt: AppSyncAPI.AWSDateTime { __data["updatedAt"] }
51+
public var createdAt: AppSyncAPI.AWSDateTime { __data["createdAt"] }
52+
public var content: String? { __data["content"] }
53+
public var owner: String? { __data["owner"] }
54+
}
55+
}
56+
}

Tests/IntegrationTestApp/AppSyncAPI/Sources/Operations/Queries/MyQuery.graphql.swift

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
//
2-
// Copyright Amazon.com Inc. or its affiliates.
3-
// All Rights Reserved.
4-
//
5-
// SPDX-License-Identifier: Apache-2.0
6-
//
1+
// @generated
2+
// This file was automatically generated and should not be edited.
73

84
@_exported import ApolloAPI
95

@@ -18,7 +14,7 @@ public class MyQuery: GraphQLQuery {
1814

1915
public struct Data: AppSyncAPI.SelectionSet {
2016
public let __data: DataDict
21-
public init(_dataDict: DataDict) { self.__data = _dataDict }
17+
public init(_dataDict: DataDict) { __data = _dataDict }
2218

2319
public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Query }
2420
public static var __selections: [ApolloAPI.Selection] { [
@@ -32,7 +28,7 @@ public class MyQuery: GraphQLQuery {
3228
/// Parent Type: `ModelTodoConnection`
3329
public struct ListTodos: AppSyncAPI.SelectionSet {
3430
public let __data: DataDict
35-
public init(_dataDict: DataDict) { self.__data = _dataDict }
31+
public init(_dataDict: DataDict) { __data = _dataDict }
3632

3733
public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.ModelTodoConnection }
3834
public static var __selections: [ApolloAPI.Selection] { [
@@ -49,7 +45,7 @@ public class MyQuery: GraphQLQuery {
4945
/// Parent Type: `Todo`
5046
public struct Item: AppSyncAPI.SelectionSet {
5147
public let __data: DataDict
52-
public init(_dataDict: DataDict) { self.__data = _dataDict }
48+
public init(_dataDict: DataDict) { __data = _dataDict }
5349

5450
public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Todo }
5551
public static var __selections: [ApolloAPI.Selection] { [

Tests/IntegrationTestApp/AppSyncAPI/Sources/Operations/Subscriptions/OnCreateSubscription.graphql.swift

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
//
2-
// Copyright Amazon.com Inc. or its affiliates.
3-
// All Rights Reserved.
4-
//
5-
// SPDX-License-Identifier: Apache-2.0
6-
//
1+
// @generated
2+
// This file was automatically generated and should not be edited.
73

84
@_exported import ApolloAPI
95

@@ -18,7 +14,7 @@ public class OnCreateSubscription: GraphQLSubscription {
1814

1915
public struct Data: AppSyncAPI.SelectionSet {
2016
public let __data: DataDict
21-
public init(_dataDict: DataDict) { self.__data = _dataDict }
17+
public init(_dataDict: DataDict) { __data = _dataDict }
2218

2319
public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Subscription }
2420
public static var __selections: [ApolloAPI.Selection] { [
@@ -32,7 +28,7 @@ public class OnCreateSubscription: GraphQLSubscription {
3228
/// Parent Type: `Todo`
3329
public struct OnCreateTodo: AppSyncAPI.SelectionSet {
3430
public let __data: DataDict
35-
public init(_dataDict: DataDict) { self.__data = _dataDict }
31+
public init(_dataDict: DataDict) { __data = _dataDict }
3632

3733
public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Todo }
3834
public static var __selections: [ApolloAPI.Selection] { [

Tests/IntegrationTestApp/AppSyncAPI/Sources/Schema/InputObjects/CreateTodoInput.graphql.swift

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
//
2-
// Copyright Amazon.com Inc. or its affiliates.
3-
// All Rights Reserved.
4-
//
5-
// SPDX-License-Identifier: Apache-2.0
6-
//
1+
// @generated
2+
// This file was automatically generated and should not be edited.
73

84
import ApolloAPI
95

106
public struct CreateTodoInput: InputObject {
117
public private(set) var __data: InputDict
128

139
public init(_ data: InputDict) {
14-
self.__data = data
10+
__data = data
1511
}
1612

1713
public init(
1814
content: GraphQLNullable<String> = nil,
1915
id: GraphQLNullable<ID> = nil
2016
) {
21-
self.__data = InputDict([
17+
__data = InputDict([
2218
"content": content,
2319
"id": id
2420
])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @generated
2+
// This file was automatically generated and should not be edited.
3+
4+
import ApolloAPI
5+
6+
public struct UpdateTodoInput: InputObject {
7+
public private(set) var __data: InputDict
8+
9+
public init(_ data: InputDict) {
10+
__data = data
11+
}
12+
13+
public init(
14+
content: GraphQLNullable<String> = nil,
15+
id: ID
16+
) {
17+
__data = InputDict([
18+
"content": content,
19+
"id": id
20+
])
21+
}
22+
23+
public var content: GraphQLNullable<String> {
24+
get { __data["content"] }
25+
set { __data["content"] = newValue }
26+
}
27+
28+
public var id: ID {
29+
get { __data["id"] }
30+
set { __data["id"] = newValue }
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
//
2-
// Copyright Amazon.com Inc. or its affiliates.
3-
// All Rights Reserved.
4-
//
5-
// SPDX-License-Identifier: Apache-2.0
6-
//
1+
// @generated
2+
// This file was automatically generated and should not be edited.
73

84
import ApolloAPI
95

@@ -12,4 +8,4 @@ public extension Objects {
128
typename: "ModelTodoConnection",
139
implementedInterfaces: []
1410
)
15-
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
//
2-
// Copyright Amazon.com Inc. or its affiliates.
3-
// All Rights Reserved.
4-
//
5-
// SPDX-License-Identifier: Apache-2.0
6-
//
1+
// @generated
2+
// This file was automatically generated and should not be edited.
73

84
import ApolloAPI
95

@@ -12,4 +8,4 @@ public extension Objects {
128
typename: "Mutation",
139
implementedInterfaces: []
1410
)
15-
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
//
2-
// Copyright Amazon.com Inc. or its affiliates.
3-
// All Rights Reserved.
4-
//
5-
// SPDX-License-Identifier: Apache-2.0
6-
//
1+
// @generated
2+
// This file was automatically generated and should not be edited.
73

84
import ApolloAPI
95

@@ -12,4 +8,4 @@ public extension Objects {
128
typename: "Query",
139
implementedInterfaces: []
1410
)
15-
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
//
2-
// Copyright Amazon.com Inc. or its affiliates.
3-
// All Rights Reserved.
4-
//
5-
// SPDX-License-Identifier: Apache-2.0
6-
//
1+
// @generated
2+
// This file was automatically generated and should not be edited.
73

84
import ApolloAPI
95

@@ -12,4 +8,4 @@ public extension Objects {
128
typename: "Subscription",
139
implementedInterfaces: []
1410
)
15-
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
//
2-
// Copyright Amazon.com Inc. or its affiliates.
3-
// All Rights Reserved.
4-
//
5-
// SPDX-License-Identifier: Apache-2.0
6-
//
1+
// @generated
2+
// This file was automatically generated and should not be edited.
73

84
import ApolloAPI
95

@@ -12,4 +8,4 @@ public extension Objects {
128
typename: "Todo",
139
implementedInterfaces: []
1410
)
15-
}
11+
}

Tests/IntegrationTestApp/AppSyncAPI/Sources/Schema/SchemaMetadata.graphql.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
//
2-
// Copyright Amazon.com Inc. or its affiliates.
3-
// All Rights Reserved.
4-
//
5-
// SPDX-License-Identifier: Apache-2.0
6-
//
1+
// @generated
2+
// This file was automatically generated and should not be edited.
73

84
import ApolloAPI
95

Tests/IntegrationTestApp/IntegrationTestApp/ContentView.swift

+20
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import SwiftUI
1313
class ContentViewModel: ObservableObject {
1414

1515
var activeSubscription: Apollo.Cancellable?
16+
var createdTodoId: String?
1617

1718
func list() {
1819
Network.shared.apolloIAM.fetch(query: MyQuery(), cachePolicy: .fetchIgnoringCacheCompletely) { result in
@@ -65,6 +66,7 @@ class ContentViewModel: ObservableObject {
6566
case .success(let graphQLResult):
6667
if let todo = graphQLResult.data?.createTodo {
6768
print("Created mutation todo ", todo.id)
69+
self.createdTodoId = todo.id
6870
}
6971
if let errors = graphQLResult.errors {
7072
print("Errors", errors)
@@ -75,6 +77,24 @@ class ContentViewModel: ObservableObject {
7577
}
7678
}
7779

80+
func updateMutation() {
81+
guard let id = createdTodoId else {
82+
return
83+
}
84+
Network.shared.apolloIAM.perform(mutation: UpdateTodoMutation(updateTodoInput: .init(id: id))) { result in
85+
switch result {
86+
case .success(let graphQLResult):
87+
if let todo = graphQLResult.data?.updateTodo {
88+
print("Update mutation todo ", todo.id)
89+
}
90+
if let errors = graphQLResult.errors {
91+
print("Errors", errors)
92+
}
93+
case .failure(let error):
94+
print("Error updating todo: \(error)")
95+
}
96+
}
97+
}
7898
}
7999

80100
struct ContentView: View {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mutation UpdateTodo($updateTodoInput: UpdateTodoInput!) {
2+
updateTodo(input: $updateTodoInput) {
3+
id
4+
updatedAt
5+
createdAt
6+
content
7+
owner
8+
}
9+
}

0 commit comments

Comments
 (0)