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

Field Merging [5/x] Move fieldMerging option to experimental #344

Open
wants to merge 2 commits into
base: Field_Merging_4_x_disable_initializers
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extension ApolloCodegenConfiguration {
public static func mock(
_ moduleType: ApolloCodegenConfiguration.SchemaTypesFileOutput.ModuleType,
options: ApolloCodegenConfiguration.OutputOptions = .init(),
experimentalFeatures: ExperimentalFeatures = .init(),
schemaNamespace: String = "TestSchema",
to path: String = "MockModulePath"
) -> Self {
Expand All @@ -42,7 +43,8 @@ extension ApolloCodegenConfiguration {
output: .init(
schemaTypes: .init(path: path, moduleType: moduleType)
),
options: options
options: options,
experimentalFeatures: experimentalFeatures
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
],
deprecatedEnumCases: .exclude,
schemaDocumentation: .exclude,
fieldMerging: .all,
cocoapodsCompatibleImportStatements: true,
warningsOnDeprecatedUsage: .exclude,
conversionStrategies:.init(
Expand All @@ -55,6 +54,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
markOperationDefinitionsAsFinal: true
),
experimentalFeatures: .init(
fieldMerging: .all,
legacySafelistingCompatibleOperations: true
),
operationManifest: .init(
Expand All @@ -69,6 +69,9 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
"""
{
"experimentalFeatures" : {
"fieldMerging" : [
"all"
],
"legacySafelistingCompatibleOperations" : true
},
"input" : {
Expand Down Expand Up @@ -100,9 +103,6 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
"inputObjects" : "none"
},
"deprecatedEnumCases" : "exclude",
"fieldMerging" : [
"all"
],
"markOperationDefinitionsAsFinal" : true,
"operationDocumentFormat" : [
"definition"
Expand Down
40 changes: 40 additions & 0 deletions Tests/ApolloCodegenTests/ApolloCodegenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2374,6 +2374,46 @@ class ApolloCodegenTests: XCTestCase {
})
}

func test__validation__givenFieldMerging_notAll_andSelectionSetInitializers_enabled_shouldThrowError() throws {
// given
let fieldMergingOptions: [ApolloCodegenConfiguration.FieldMerging] = [
.none,
.ancestors,
.namedFragments,
.siblings,
[.ancestors, .namedFragments],
[.siblings, .ancestors],
[.siblings, .namedFragments]
]
let initializerOptions: [ApolloCodegenConfiguration.SelectionSetInitializers] = [
.all,
.localCacheMutations,
.operations,
.namedFragments,
.fragment(named: "TestFragment"),
[.operations, .localCacheMutations]
]

for fieldMergingOption in fieldMergingOptions {
for initializerOption in initializerOptions {

let config = ApolloCodegenConfiguration.mock(
.other,
options: .init(
selectionSetInitializers: initializerOption
),
experimentalFeatures: .init(
fieldMerging: fieldMergingOption
)
)

// then
expect(try ApolloCodegen._validate(config: config))
.to(throwError(ApolloCodegen.Error.fieldMergingIncompatibility))
}
}
}

// MARK: Path Match Exclusion Tests

func test__match__givenFilesInSpecialExcludedPaths_shouldNotReturnExcludedPaths() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,9 @@ class FragmentTemplateTests: XCTestCase {
// when
try await buildSubjectAndFragment(config: .mock(
options: .init(
selectionSetInitializers: [.all],
fieldMerging: test
)
selectionSetInitializers: [.all]
),
experimentalFeatures: .init(fieldMerging: test)
))

let actual = renderSubject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
throw XCTSkip("Skipped in PR #235 - must be reverted when the feature/defer-execution-networking branch is merged into main!")

// given
schemaSDL = """

Check warning on line 315 in Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplateTests.swift

View workflow job for this annotation

GitHub Actions / Codegen Lib Unit Tests - macOS

code after 'throw' will never be executed
type Query {
allAnimals: [Animal!]
}
Expand Down Expand Up @@ -352,7 +352,7 @@
throw XCTSkip("Skipped in PR #235 - must be reverted when the feature/defer-execution-networking branch is merged into main!")

// given
schemaSDL = """

Check warning on line 355 in Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplateTests.swift

View workflow job for this annotation

GitHub Actions / Codegen Lib Unit Tests - macOS

code after 'throw' will never be executed
type Query {
allAnimals: [Animal!]
}
Expand Down Expand Up @@ -394,7 +394,7 @@
throw XCTSkip("Skipped in PR #235 - must be reverted when the feature/defer-execution-networking branch is merged into main!")

// given
schemaSDL = """

Check warning on line 397 in Tests/ApolloCodegenTests/CodeGeneration/Templates/OperationDefinitionTemplateTests.swift

View workflow job for this annotation

GitHub Actions / Codegen Lib Unit Tests - macOS

code after 'throw' will never be executed
type Query {
allAnimals: [Animal!]
}
Expand Down Expand Up @@ -669,9 +669,9 @@

config = .mock(
options: .init(
selectionSetInitializers: [.all],
fieldMerging: test
)
selectionSetInitializers: [.all]
),
experimentalFeatures: .init(fieldMerging: test)
)

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SelectionSetTemplate_ErrorHandling_Tests: XCTestCase {
let config = ApolloCodegenConfiguration.mock(
schemaNamespace: "TestSchema",
output: .mock(moduleType: .swiftPackageManager, operations: .inSchemaModule),
options: .init(
experimentalFeatures: .init(
fieldMerging: fieldMerging
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class SelectionSetTemplate_FieldMerging_Tests: XCTestCase {
options: .init(
additionalInflectionRules: inflectionRules,
schemaDocumentation: schemaDocumentation,
fieldMerging: fieldMerging,
cocoapodsCompatibleImportStatements: cocoapodsImportStatements,
warningsOnDeprecatedUsage: warningsOnDeprecatedUsage,
conversionStrategies: conversionStrategies
)
),
experimentalFeatures: .init(fieldMerging: fieldMerging)
))
let mockTemplateRenderer = MockTemplateRenderer(
target: .operationFile(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extension ApolloCodegen {
case invalidConfiguration(message: String)
case invalidSchemaName(_ name: String, message: String)
case targetNameConflict(name: String)
case fieldMergingIncompatibility

public var errorDescription: String? {
switch self {
Expand Down Expand Up @@ -52,6 +53,13 @@ extension ApolloCodegen {
Target name '\(name)' conflicts with a reserved library name. Please choose a different \
target name.
"""
case .fieldMergingIncompatibility:
return """
Options for disabling 'fieldMerging' and enabling 'selectionSetInitializers' are
incompatible.

Please set either 'fieldMerging' to 'all' or 'selectionSetInitializers' to be empty.
"""
}
}
}
Expand Down