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

chore: add graphql files #17

Merged
merged 2 commits into from
Sep 5, 2024
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// @generated
// This file was automatically generated and should not be edited.

@_exported import ApolloAPI

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

public struct Data: AppSyncAPI.SelectionSet {
public let __data: DataDict
public init(_dataDict: DataDict) { self.__data = _dataDict }
public init(_dataDict: DataDict) { __data = _dataDict }

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

public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Todo }
public static var __selections: [ApolloAPI.Selection] { [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// @generated
// This file was automatically generated and should not be edited.

@_exported import ApolloAPI

public class UpdateTodoMutation: GraphQLMutation {
public static let operationName: String = "UpdateTodo"
public static let operationDocument: ApolloAPI.OperationDocument = .init(
definition: .init(
#"mutation UpdateTodo($updateTodoInput: UpdateTodoInput!) { updateTodo(input: $updateTodoInput) { __typename id updatedAt createdAt content owner } }"#
))

public var updateTodoInput: UpdateTodoInput

public init(updateTodoInput: UpdateTodoInput) {
self.updateTodoInput = updateTodoInput
}

public var __variables: Variables? { ["updateTodoInput": updateTodoInput] }

public struct Data: AppSyncAPI.SelectionSet {
public let __data: DataDict
public init(_dataDict: DataDict) { __data = _dataDict }

public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Mutation }
public static var __selections: [ApolloAPI.Selection] { [
.field("updateTodo", UpdateTodo?.self, arguments: ["input": .variable("updateTodoInput")]),
] }

public var updateTodo: UpdateTodo? { __data["updateTodo"] }

/// UpdateTodo
///
/// Parent Type: `Todo`
public struct UpdateTodo: AppSyncAPI.SelectionSet {
public let __data: DataDict
public init(_dataDict: DataDict) { __data = _dataDict }

public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Todo }
public static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("id", AppSyncAPI.ID.self),
.field("updatedAt", AppSyncAPI.AWSDateTime.self),
.field("createdAt", AppSyncAPI.AWSDateTime.self),
.field("content", String?.self),
.field("owner", String?.self),
] }

public var id: AppSyncAPI.ID { __data["id"] }
public var updatedAt: AppSyncAPI.AWSDateTime { __data["updatedAt"] }
public var createdAt: AppSyncAPI.AWSDateTime { __data["createdAt"] }
public var content: String? { __data["content"] }
public var owner: String? { __data["owner"] }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// @generated
// This file was automatically generated and should not be edited.

@_exported import ApolloAPI

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

public struct Data: AppSyncAPI.SelectionSet {
public let __data: DataDict
public init(_dataDict: DataDict) { self.__data = _dataDict }
public init(_dataDict: DataDict) { __data = _dataDict }

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

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

public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Todo }
public static var __selections: [ApolloAPI.Selection] { [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// @generated
// This file was automatically generated and should not be edited.

@_exported import ApolloAPI

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

public struct Data: AppSyncAPI.SelectionSet {
public let __data: DataDict
public init(_dataDict: DataDict) { self.__data = _dataDict }
public init(_dataDict: DataDict) { __data = _dataDict }

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

public static var __parentType: any ApolloAPI.ParentType { AppSyncAPI.Objects.Todo }
public static var __selections: [ApolloAPI.Selection] { [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

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

public init(_ data: InputDict) {
self.__data = data
__data = data
}

public init(
content: GraphQLNullable<String> = nil,
id: GraphQLNullable<ID> = nil
) {
self.__data = InputDict([
__data = InputDict([
"content": content,
"id": id
])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

public struct UpdateTodoInput: InputObject {
public private(set) var __data: InputDict

public init(_ data: InputDict) {
__data = data
}

public init(
content: GraphQLNullable<String> = nil,
id: ID
) {
__data = InputDict([
"content": content,
"id": id
])
}

public var content: GraphQLNullable<String> {
get { __data["content"] }
set { __data["content"] = newValue }
}

public var id: ID {
get { __data["id"] }
set { __data["id"] = newValue }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

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

import ApolloAPI

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

import ApolloAPI

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

import ApolloAPI

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

import ApolloAPI

Expand All @@ -12,4 +8,4 @@ public extension Objects {
typename: "Todo",
implementedInterfaces: []
)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

Expand Down
20 changes: 20 additions & 0 deletions Tests/IntegrationTestApp/IntegrationTestApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SwiftUI
class ContentViewModel: ObservableObject {

var activeSubscription: Apollo.Cancellable?
var createdTodoId: String?

func list() {
Network.shared.apolloIAM.fetch(query: MyQuery(), cachePolicy: .fetchIgnoringCacheCompletely) { result in
Expand Down Expand Up @@ -65,6 +66,7 @@ class ContentViewModel: ObservableObject {
case .success(let graphQLResult):
if let todo = graphQLResult.data?.createTodo {
print("Created mutation todo ", todo.id)
self.createdTodoId = todo.id
}
if let errors = graphQLResult.errors {
print("Errors", errors)
Expand All @@ -75,6 +77,24 @@ class ContentViewModel: ObservableObject {
}
}

func updateMutation() {
guard let id = createdTodoId else {
return
}
Network.shared.apolloIAM.perform(mutation: UpdateTodoMutation(updateTodoInput: .init(id: id))) { result in
switch result {
case .success(let graphQLResult):
if let todo = graphQLResult.data?.updateTodo {
print("Update mutation todo ", todo.id)
}
if let errors = graphQLResult.errors {
print("Errors", errors)
}
case .failure(let error):
print("Error updating todo: \(error)")
}
}
}
}

struct ContentView: View {
Expand Down
9 changes: 9 additions & 0 deletions Tests/IntegrationTestApp/graphql/CreateTodo.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mutation CreateTodo($createTodoInput: CreateTodoInput!) {
createTodo(input: $createTodoInput) {
id
updatedAt
createdAt
content
owner
}
}
9 changes: 9 additions & 0 deletions Tests/IntegrationTestApp/graphql/SubscribeTodo.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
subscription onCreateSubscription {
onCreateTodo {
id
updatedAt
createdAt
content
owner
}
}
12 changes: 12 additions & 0 deletions Tests/IntegrationTestApp/graphql/TodoList.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
query MyQuery {
listTodos {
items {
id
updatedAt
createdAt
content
owner
}
nextToken
}
}
Loading
Loading