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

Add and test omitDeprecatedEnumCases option #1053

Merged
merged 1 commit into from
Feb 29, 2020
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
10 changes: 9 additions & 1 deletion Sources/ApolloCodegenLib/ApolloCodegenOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)")
}
Expand All @@ -141,6 +145,10 @@ public struct ApolloCodegenOptions {
arguments.append("--operationIdsPath=\(idsURL.path)")
}

if self.omitDeprecatedEnumCases {
arguments.append("--omitDeprecatedEnumCases")
}

if self.passthroughCustomScalars {
arguments.append("--passthroughCustomScalars")
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/ApolloCodegenTests/ApolloCodegenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -67,6 +68,7 @@ class ApolloCodegenTests: XCTestCase {
includes: "*.graphql",
mergeInFieldsFromFragmentSpreads: false,
namespace: namespace,
omitDeprecatedEnumCases: true,
only: only,
operationIDsURL: operationIDsURL,
outputFormat: .multipleFiles(inFolderAtURL: output),
Expand All @@ -85,6 +87,7 @@ class ApolloCodegenTests: XCTestCase {
}
XCTAssertTrue(options.passthroughCustomScalars)
XCTAssertEqual(options.urlToSchemaFile, schema)
XCTAssertTrue(options.omitDeprecatedEnumCases)


XCTAssertEqual(options.arguments, [
Expand All @@ -96,6 +99,7 @@ class ApolloCodegenTests: XCTestCase {
"--namespace=\(namespace)",
"--only=\(only.path)",
"--operationIdsPath=\(operationIDsURL.path)",
"--omitDeprecatedEnumCases",
"--passthroughCustomScalars",
output.path,
])
Expand Down