Skip to content

Commit

Permalink
Generate Operation Variables & Field Arguments (#2163)
Browse files Browse the repository at this point in the history
* Render Operation Variable - single variable

* Operation Variables - Multiple Variables

* WIP: Operation Variable - nullables

* Recfactored to add InputValueRenderable

Finished implementation of operation variable generation

* Fix renamed but not deleted file

* Add ExpressibleBy Literals to GraphQLNullable

* Correct OperationVariable rendering test behavior

* WIP: Implementing rendering

* Fix template string indentation

* Add operation variable default values to CompilationResult

* Add pet adoption mutation

* Add public modifier to input object template

* WIP:  Fixing Input Object Accessors

* Add public to input object init and fields

* Generate InputObject fields with dynamic member accessors

* Rename input object "dict" to "data"

* Added PetSearchQuery to AnimalKingdom API

* Fixed rendering of input enum values

* Fixed conversion of default value dictionary literal to InputObject

* WIP

* Restructured tests to be accurate for behavior with initializing inpuit object default values directly

* Changed Implementation for direct input value initialization

* WIP: FieldArgument Rendering

* Fix field argument rendering to use literals

* Regenerate AnimalKingdomAPI with field arguments
  • Loading branch information
AnthonyMDev authored Feb 22, 2022
1 parent 1e71ad0 commit ad37c60
Show file tree
Hide file tree
Showing 45 changed files with 2,009 additions and 320 deletions.
108 changes: 102 additions & 6 deletions Apollo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions Apollo.xcodeproj/xcshareddata/xcschemes/AnimalKingdomAPI.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DE3C7A00260A6B9800D2F4FF"
BuildableName = "AnimalKingdomAPI.framework"
BlueprintName = "AnimalKingdomAPI"
ReferencedContainer = "container:Apollo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DE3C7A00260A6B9800D2F4FF"
BuildableName = "AnimalKingdomAPI.framework"
BlueprintName = "AnimalKingdomAPI"
ReferencedContainer = "container:Apollo.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ public class AllAnimalsQuery: GraphQLQuery {

public static var __parentType: ParentType { .Object(AnimalKingdomAPI.Bird.self) }
public static var selections: [Selection] { [
.field("wingspan", Int.self),
.field("wingspan", Float.self),
] }

public var wingspan: Int { data["wingspan"] }
public var wingspan: Float { data["wingspan"] }
public var height: Height { data["height"] }
public var species: String { data["species"] }
public var skinCovering: GraphQLEnum<SkinCovering>? { data["skinCovering"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ public struct ClassroomPetDetails: AnimalKingdomAPI.SelectionSet, Fragment {

public static var __parentType: ParentType { .Object(AnimalKingdomAPI.Bird.self) }
public static var selections: [Selection] { [
.field("wingspan", Int.self),
.field("wingspan", Float.self),
] }

public var wingspan: Int { data["wingspan"] }
public var wingspan: Float { data["wingspan"] }
public var species: String { data["species"] }
public var humanName: String? { data["humanName"] }
public var laysEggs: Bool { data["laysEggs"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public class ClassroomPetsQuery: GraphQLQuery {
public var species: String { data["species"] }
public var humanName: String? { data["humanName"] }
public var laysEggs: Bool { data["laysEggs"] }
public var wingspan: Int { data["wingspan"] }
public var wingspan: Float { data["wingspan"] }

public struct Fragments: FragmentContainer {
public let data: DataDict
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.

import ApolloAPI

public class PetAdoptionMutation: GraphQLMutation {
public let operationName: String = "PetAdoptionMutation"
public let document: DocumentType = .notPersisted(
definition: .init(
"""
mutation PetAdoptionMutation($input: PetAdoptionInput!) {
adoptPet(input: $input) {
id
humanName
}
}
"""
))

public var input: PetAdoptionInput

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

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

public struct Data: AnimalKingdomAPI.SelectionSet {
public let data: DataDict
public init(data: DataDict) { self.data = data }

public static var __parentType: ParentType { .Object(AnimalKingdomAPI.Mutation.self) }
public static var selections: [Selection] { [
.field("adoptPet", AdoptPet.self, arguments: ["input": .variable("input")]),
] }

public var adoptPet: AdoptPet { data["adoptPet"] }

/// AdoptPet
public struct AdoptPet: AnimalKingdomAPI.SelectionSet {
public let data: DataDict
public init(data: DataDict) { self.data = data }

public static var __parentType: ParentType { .Interface(AnimalKingdomAPI.Pet.self) }
public static var selections: [Selection] { [
.field("id", ID.self),
.field("humanName", String?.self),
] }

public var id: ID { data["id"] }
public var humanName: String? { data["humanName"] }
}
}
}
67 changes: 67 additions & 0 deletions Sources/AnimalKingdomAPI/Generated/Operations/PetSearchQuery.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

public class PetSearchQuery: GraphQLQuery {
public let operationName: String = "PetSearch"
public let document: DocumentType = .notPersisted(
definition: .init(
"""
query PetSearch($filters: PetSearchFilters = {species: ["Dog", "Cat"], size: SMALL, measurements: {height: 10.5, weight: 5.0}}) {
pets(filters: $filters) {
id
humanName
}
}
"""
))

public var filters: GraphQLNullable<PetSearchFilters>

public init(filters: GraphQLNullable<PetSearchFilters> = .init(
PetSearchFilters(
species: ["Dog", "Cat"],
size: .init(.SMALL),
measurements: .init(
MeasurementsInput(
height: 10.5,
weight: 5.0
)
)
)
)) {
self.filters = filters
}

public var variables: Variables? {
["filters": filters]
}

public struct Data: AnimalKingdomAPI.SelectionSet {
public let data: DataDict
public init(data: DataDict) { self.data = data }

public static var __parentType: ParentType { .Object(AnimalKingdomAPI.Query.self) }
public static var selections: [Selection] { [
.field("pets", [Pet].self, arguments: ["filters": .variable("filters")]),
] }

public var pets: [Pet] { data["pets"] }

/// Pet
public struct Pet: AnimalKingdomAPI.SelectionSet {
public let data: DataDict
public init(data: DataDict) { self.data = data }

public static var __parentType: ParentType { .Interface(AnimalKingdomAPI.Pet.self) }
public static var selections: [Selection] { [
.field("id", ID.self),
.field("humanName", String?.self),
] }

public var id: ID { data["id"] }
public var humanName: String? { data["humanName"] }
}
}
}
4 changes: 2 additions & 2 deletions Sources/AnimalKingdomAPI/Generated/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
.library(name: "AnimalKingdomAPI", targets: ["AnimalKingdomAPI"]),
],
dependencies: [
.package(url: "https://github.com/apollographql/apollo-ios.git", .branch("release/1.0-alpha-incubating")),
.package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.0.0-alpha.1"),
],
targets: [
.target(
Expand All @@ -25,4 +25,4 @@ let package = Package(
path: "."
),
]
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

public struct MeasurementsInput: InputObject {
public private(set) var data: InputDict

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

public init(
height: Float,
weight: Float,
wingspan: GraphQLNullable<Float> = nil
) {
data = InputDict([
"height": height,
"weight": weight,
"wingspan": wingspan
])
}

public var height: Float {
get { data.height }
set { data.height = newValue }
}

public var weight: Float {
get { data.weight }
set { data.weight = newValue }
}

public var wingspan: GraphQLNullable<Float> {
get { data.wingspan }
set { data.wingspan = newValue }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

public struct PetAdoptionInput: InputObject {
public private(set) var data: InputDict

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

public init(
ownerID: ID,
petID: ID,
humanName: GraphQLNullable<String> = nil,
favoriteToy: String,
isSpayedOrNeutered: Bool?,
measurements: GraphQLNullable<MeasurementsInput> = nil
) {
data = InputDict([
"ownerID": ownerID,
"petID": petID,
"humanName": humanName,
"favoriteToy": favoriteToy,
"isSpayedOrNeutered": isSpayedOrNeutered,
"measurements": measurements
])
}

public var ownerID: ID {
get { data.ownerID }
set { data.ownerID = newValue }
}

public var petID: ID {
get { data.petID }
set { data.petID = newValue }
}

public var humanName: GraphQLNullable<String> {
get { data.humanName }
set { data.humanName = newValue }
}

public var favoriteToy: String {
get { data.favoriteToy }
set { data.favoriteToy = newValue }
}

public var isSpayedOrNeutered: Bool? {
get { data.isSpayedOrNeutered }
set { data.isSpayedOrNeutered = newValue }
}

public var measurements: GraphQLNullable<MeasurementsInput> {
get { data.measurements }
set { data.measurements = newValue }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

public struct PetSearchFilters: InputObject {
public private(set) var data: InputDict

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

public init(
species: [String],
size: GraphQLNullable<GraphQLEnum<RelativeSize>> = nil,
measurements: GraphQLNullable<MeasurementsInput> = nil
) {
data = InputDict([
"species": species,
"size": size,
"measurements": measurements
])
}

public var species: [String] {
get { data.species }
set { data.species = newValue }
}

public var size: GraphQLNullable<GraphQLEnum<RelativeSize>> {
get { data.size }
set { data.size = newValue }
}

public var measurements: GraphQLNullable<MeasurementsInput> {
get { data.measurements }
set { data.measurements = newValue }
}
}
Loading

0 comments on commit ad37c60

Please sign in to comment.