From c19473cdb2764949b6120e384fd88ce43241f4a3 Mon Sep 17 00:00:00 2001
From: Ellen Shapiro <designatednerd@gmail.com>
Date: Sat, 29 Feb 2020 11:56:34 -0600
Subject: [PATCH] Add and test `omitDeprecatedEnumCases` option

---
 Sources/ApolloCodegenLib/ApolloCodegenOptions.swift | 10 +++++++++-
 Tests/ApolloCodegenTests/ApolloCodegenTests.swift   |  4 ++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Sources/ApolloCodegenLib/ApolloCodegenOptions.swift b/Sources/ApolloCodegenLib/ApolloCodegenOptions.swift
index 1e26098a50..4275b57add 100644
--- a/Sources/ApolloCodegenLib/ApolloCodegenOptions.swift
+++ b/Sources/ApolloCodegenLib/ApolloCodegenOptions.swift
@@ -41,6 +41,7 @@ public struct ApolloCodegenOptions {
   let mergeInFieldsFromFragmentSpreads: Bool
   let namespace: String?
   let only: URL?
+  let omitDeprecatedEnumCases: Bool
   let operationIDsURL: URL?
   let outputFormat: OutputFormat
   let passthroughCustomScalars: Bool
@@ -56,6 +57,7 @@ public struct ApolloCodegenOptions {
   ///  - includes: Glob of files to search for GraphQL operations. This should be used to find queries *and* any client schema extensions. Defaults to `./**/*.graphql`, which will search for `.graphql` files throughout all subfolders of the folder where the script is run.
   ///  - mergeInFieldsFromFragmentSpreads: Set true to merge fragment fields onto its enclosing type. Defaults to true.
   ///  - namespace: [optional] The namespace to emit generated code into. Defaults to nil.
+  ///  - omitDeprecatedEnumCases: Whether deprecated enum cases should be omitted from generated code. Defaults to false.
   ///  - only: [optional] Parse all input files, but only output generated code for the file at this URL if non-nil. Defaults to nil.
   ///  - operationIDsURL: [optional] Path to an operation id JSON map file. If specified, also stores the operation ids (hashes) as properties on operation types. Defaults to nil.
   ///  - outputFormat: The `OutputFormat` enum option to use to output generated code.
@@ -67,6 +69,7 @@ public struct ApolloCodegenOptions {
               includes: String = "./**/*.graphql",
               mergeInFieldsFromFragmentSpreads: Bool = true,
               namespace: String? = nil,
+              omitDeprecatedEnumCases: Bool = false,
               only: URL? = nil,
               operationIDsURL: URL? = nil,
               outputFormat: OutputFormat,
@@ -78,6 +81,7 @@ public struct ApolloCodegenOptions {
     self.includes = includes
     self.mergeInFieldsFromFragmentSpreads = mergeInFieldsFromFragmentSpreads
     self.namespace = namespace
+    self.omitDeprecatedEnumCases = omitDeprecatedEnumCases
     self.only = only
     self.operationIDsURL = operationIDsURL
     self.outputFormat = outputFormat
@@ -132,7 +136,7 @@ public struct ApolloCodegenOptions {
     if let namespace = self.namespace {
       arguments.append("--namespace=\(namespace)")
     }
-    
+
     if let only = only {
       arguments.append("--only=\(only.path)")
     }
@@ -141,6 +145,10 @@ public struct ApolloCodegenOptions {
       arguments.append("--operationIdsPath=\(idsURL.path)")
     }
     
+    if self.omitDeprecatedEnumCases {
+      arguments.append("--omitDeprecatedEnumCases")
+    }
+    
     if self.passthroughCustomScalars {
       arguments.append("--passthroughCustomScalars")
     }
diff --git a/Tests/ApolloCodegenTests/ApolloCodegenTests.swift b/Tests/ApolloCodegenTests/ApolloCodegenTests.swift
index b339cb16c3..1150b9b89a 100644
--- a/Tests/ApolloCodegenTests/ApolloCodegenTests.swift
+++ b/Tests/ApolloCodegenTests/ApolloCodegenTests.swift
@@ -41,6 +41,7 @@ class ApolloCodegenTests: XCTestCase {
     case .multipleFiles:
       XCTFail("Nope, this should be a single file!")
     }
+    XCTAssertFalse(options.omitDeprecatedEnumCases)
     XCTAssertFalse(options.passthroughCustomScalars)
     XCTAssertEqual(options.urlToSchemaFile, schema)
     
@@ -67,6 +68,7 @@ class ApolloCodegenTests: XCTestCase {
                                        includes: "*.graphql",
                                        mergeInFieldsFromFragmentSpreads: false,
                                        namespace: namespace,
+                                       omitDeprecatedEnumCases: true,
                                        only: only,
                                        operationIDsURL: operationIDsURL,
                                        outputFormat: .multipleFiles(inFolderAtURL: output),
@@ -85,6 +87,7 @@ class ApolloCodegenTests: XCTestCase {
     }
     XCTAssertTrue(options.passthroughCustomScalars)
     XCTAssertEqual(options.urlToSchemaFile, schema)
+    XCTAssertTrue(options.omitDeprecatedEnumCases)
     
     
     XCTAssertEqual(options.arguments, [
@@ -96,6 +99,7 @@ class ApolloCodegenTests: XCTestCase {
       "--namespace=\(namespace)",
       "--only=\(only.path)",
       "--operationIdsPath=\(operationIDsURL.path)",
+      "--omitDeprecatedEnumCases",
       "--passthroughCustomScalars",
       output.path,
     ])