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

feature: @oneOf input object support #537

Merged
merged 16 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
Expand Up @@ -60,10 +60,7 @@ public class AllAnimalsLocalCacheMutation: LocalCacheMutation {
set { __data["skinCovering"] = newValue }
}

public var asBird: AsBird? {
get { _asInlineFragment() }
set { if let newData = newValue?.__data._data { __data._data = newData }}
}
public var asBird: AsBird? { _asInlineFragment() }

public init(
__typename: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// @generated
// This file was automatically generated and should not be edited.

@_exported import ApolloAPI

public class FindPetQuery: GraphQLQuery {
public static let operationName: String = "FindPet"
public static let operationDocument: ApolloAPI.OperationDocument = .init(
definition: .init(
#"query FindPet($input: PetSearchInput!) { findPet(input: $input) { __typename id humanName } }"#
))

public var input: PetSearchInput

public init(input: PetSearchInput) {
self.input = input
}

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

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

public static var __parentType: any ApolloAPI.ParentType { AnimalKingdomAPI.Objects.Query }
public static var __selections: [ApolloAPI.Selection] { [
.field("findPet", [FindPet].self, arguments: ["input": .variable("input")]),
] }

public var findPet: [FindPet] { __data["findPet"] }

public init(
findPet: [FindPet]
) {
self.init(_dataDict: DataDict(
data: [
"__typename": AnimalKingdomAPI.Objects.Query.typename,
"findPet": findPet._fieldData,
],
fulfilledFragments: [
ObjectIdentifier(FindPetQuery.Data.self)
]
))
}

/// FindPet
///
/// Parent Type: `Pet`
public struct FindPet: AnimalKingdomAPI.SelectionSet {
public let __data: DataDict
public init(_dataDict: DataDict) { __data = _dataDict }

public static var __parentType: any ApolloAPI.ParentType { AnimalKingdomAPI.Interfaces.Pet }
public static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("id", AnimalKingdomAPI.ID.self),
.field("humanName", String?.self),
] }

public var id: AnimalKingdomAPI.ID { __data["id"] }
public var humanName: String? { __data["humanName"] }

public init(
__typename: String,
id: AnimalKingdomAPI.ID,
humanName: String? = nil
) {
self.init(_dataDict: DataDict(
data: [
"__typename": __typename,
"id": id,
"humanName": humanName,
],
fulfilledFragments: [
ObjectIdentifier(FindPetQuery.Data.FindPet.self)
]
))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

public enum PetSearchInput: OneOfInputObject {
case ownerID(ID)
case petID(ID)
case searchFilters(PetSearchFilters)

public var __data: InputDict {
switch self {
case .ownerID(let value):
return InputDict(["ownerID": value])
case .petID(let value):
return InputDict(["petID": value])
case .searchFilters(let value):
return InputDict(["searchFilters": value])
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public enum SchemaMetadata: ApolloAPI.SchemaMetadata {

public static func objectType(forTypename typename: String) -> ApolloAPI.Object? {
switch typename {
case "Query": return AnimalKingdomAPI.Objects.Query
case "Human": return AnimalKingdomAPI.Objects.Human
case "Bird": return AnimalKingdomAPI.Objects.Bird
case "Cat": return AnimalKingdomAPI.Objects.Cat
case "Crocodile": return AnimalKingdomAPI.Objects.Crocodile
case "Dog": return AnimalKingdomAPI.Objects.Dog
case "Bird": return AnimalKingdomAPI.Objects.Bird
case "Fish": return AnimalKingdomAPI.Objects.Fish
case "Rat": return AnimalKingdomAPI.Objects.Rat
case "PetRock": return AnimalKingdomAPI.Objects.PetRock
case "Crocodile": return AnimalKingdomAPI.Objects.Crocodile
case "Height": return AnimalKingdomAPI.Objects.Height
case "Human": return AnimalKingdomAPI.Objects.Human
case "Mutation": return AnimalKingdomAPI.Objects.Mutation
case "PetRock": return AnimalKingdomAPI.Objects.PetRock
case "Query": return AnimalKingdomAPI.Objects.Query
case "Rat": return AnimalKingdomAPI.Objects.Rat
default: return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AnimalKingdomAPI

public extension MockObject {
typealias Animal = Interface
typealias WarmBlooded = Interface
typealias Pet = Interface
typealias HousePet = Interface
typealias Pet = Interface
typealias WarmBlooded = Interface
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Query: MockObject {
public struct MockFields {
@Field<[Animal]>("allAnimals") public var allAnimals
@Field<[ClassroomPet?]>("classroomPets") public var classroomPets
@Field<[Pet]>("findPet") public var findPet
@Field<[Pet]>("pets") public var pets
}
}
Expand All @@ -20,11 +21,13 @@ public extension Mock where O == Query {
convenience init(
allAnimals: [(any AnyMock)]? = nil,
classroomPets: [(any AnyMock)?]? = nil,
findPet: [(any AnyMock)]? = nil,
pets: [(any AnyMock)]? = nil
) {
self.init()
_setList(allAnimals, for: \.allAnimals)
_setList(classroomPets, for: \.classroomPets)
_setList(findPet, for: \.findPet)
_setList(pets, for: \.pets)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ type Query {
allAnimals: [Animal!]!
classroomPets: [ClassroomPet]
pets(filters: PetSearchFilters!): [Pet!]!
findPet(input: PetSearchInput!): [Pet!]!
}

type Mutation {
Expand All @@ -12,6 +13,12 @@ scalar CustomDate

scalar Object

input PetSearchInput @oneOf {
ownerID: ID
petID: ID
searchFilters: PetSearchFilters
}

input PetAdoptionInput {
ownerID: ID!
petID: ID!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query FindPet($input: PetSearchInput!) {
findPet(input: $input) {
id
humanName
}
}

Loading
Loading