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

fix: Use public modifier only when required by module type #2313

Merged
merged 17 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
6133fa4
fix: Correctly add public modifier on schema objects when required by…
calvincestari Jun 9, 2022
69e311b
fix: Correctly add public modifier on schema Interfaces when required…
calvincestari Jun 10, 2022
a2f5663
fix: Correctly add public modifier on schema CustomScalars when requi…
calvincestari Jun 10, 2022
dded64b
fix: Correctly add public modifier on schema Enums when required by m…
calvincestari Jun 11, 2022
239121f
fix: Correctly add public modifier on schema Unions when required by …
calvincestari Jun 13, 2022
5472fe7
fix: Correctly add public modifier on schema InputObjects when requir…
calvincestari Jun 13, 2022
0da925c
fix: Correctly add public modifier on schema template definitions whe…
calvincestari Jun 13, 2022
276d9d9
fix: Correctly add public modifier on schema Fragment definitions whe…
calvincestari Jun 13, 2022
e8243f2
fix: Correctly add public modifier on schema operation definitions wh…
calvincestari Jun 13, 2022
e3957ff
refactor: Return empty string instead of requiring callers to use nil…
calvincestari Jun 13, 2022
594e641
chore: fix deprecation tests after rebase
calvincestari Jun 13, 2022
0415a3c
fix: Remove tab indents and fix newly added FragmentTemplateTest cases
calvincestari Jun 14, 2022
d7c5b0b
fix: Correctly add public modifier on schema local mutation definitio…
calvincestari Jun 14, 2022
cec5ada
Add local cache mutation typealias definitions to embedded template f…
calvincestari Jun 14, 2022
ef4bc5b
chore: Rename test file to match XCTestCase definition name
calvincestari Jun 14, 2022
5eb0a7d
tests: Update subject to use a lowercase name as the input
calvincestari Jun 14, 2022
f71d41d
tests: Rename tests to remove mention of casing when the test does no…
calvincestari Jun 14, 2022
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
8 changes: 4 additions & 4 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
9BAEEBF32346DDAD00808306 /* CodegenLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEBF22346DDAD00808306 /* CodegenLogger.swift */; };
9BAEEBF72346F0A000808306 /* StaticString+Apollo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEBF62346F0A000808306 /* StaticString+Apollo.swift */; };
9BAEEC01234BB8FD00808306 /* ApolloCodegenLib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B7B6F47233C26D100F32205 /* ApolloCodegenLib.framework */; };
9BAEEC10234BB95B00808306 /* FileManagerExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC0D234BB95B00808306 /* FileManagerExtensionsTests.swift */; };
9BAEEC10234BB95B00808306 /* FileManagerExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC0D234BB95B00808306 /* FileManagerExtensionTests.swift */; };
9BAEEC17234C275600808306 /* ApolloSchemaPublicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC16234C275600808306 /* ApolloSchemaPublicTests.swift */; };
9BAEEC19234C297800808306 /* ApolloCodegenConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC18234C297800808306 /* ApolloCodegenConfigurationTests.swift */; };
9BC139A424EDCA6C00876D29 /* MaxRetryInterceptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BC139A224EDCA4400876D29 /* MaxRetryInterceptorTests.swift */; };
Expand Down Expand Up @@ -924,7 +924,7 @@
9BAEEBF62346F0A000808306 /* StaticString+Apollo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StaticString+Apollo.swift"; sourceTree = "<group>"; };
9BAEEBFC234BB8FD00808306 /* ApolloCodegenTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ApolloCodegenTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9BAEEC0C234BB95B00808306 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9BAEEC0D234BB95B00808306 /* FileManagerExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileManagerExtensionsTests.swift; sourceTree = "<group>"; };
9BAEEC0D234BB95B00808306 /* FileManagerExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileManagerExtensionTests.swift; sourceTree = "<group>"; };
9BAEEC11234BBA9200808306 /* CodegenTestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodegenTestHelper.swift; sourceTree = "<group>"; };
9BAEEC16234C275600808306 /* ApolloSchemaPublicTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloSchemaPublicTests.swift; sourceTree = "<group>"; };
9BAEEC18234C297800808306 /* ApolloCodegenConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloCodegenConfigurationTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1867,7 +1867,7 @@
E61EF712275EC99A00191DA7 /* ApolloCodegenTests.swift */,
9BAEEC18234C297800808306 /* ApolloCodegenConfigurationTests.swift */,
E6908E54282694630054682B /* ApolloCodegenConfigurationCodableTests.swift */,
9BAEEC0D234BB95B00808306 /* FileManagerExtensionsTests.swift */,
9BAEEC0D234BB95B00808306 /* FileManagerExtensionTests.swift */,
9B4751AC2575B5070001FB87 /* PluralizerTests.swift */,
9B8C3FB4248DA3E000707B13 /* URLExtensionsTests.swift */,
9BAEEC0C234BB95B00808306 /* Info.plist */,
Expand Down Expand Up @@ -3926,7 +3926,7 @@
buildActionMask = 2147483647;
files = (
E669352D2803EF67004E1FFC /* CustomScalarTemplateTests.swift in Sources */,
9BAEEC10234BB95B00808306 /* FileManagerExtensionsTests.swift in Sources */,
9BAEEC10234BB95B00808306 /* FileManagerExtensionTests.swift in Sources */,
E6D90D09278FA5C3009CAC5D /* InputObjectFileGeneratorTests.swift in Sources */,
E674DB43274C0AD9009BB90E /* GlobTests.swift in Sources */,
DE223C1C271F3288004A0148 /* AnimalKingdomIRCreationTests.swift in Sources */,
Expand Down
22 changes: 15 additions & 7 deletions Sources/ApolloCodegenLib/ApolloCodegen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class ApolloCodegen {
for fragment in compilationResult.fragments {
try autoreleasepool {
let irFragment = ir.build(fragment: fragment)
try FragmentFileGenerator(irFragment: irFragment, schema: ir.schema)
try FragmentFileGenerator(irFragment: irFragment, schema: ir.schema, config: config)
.generate(forConfig: config, fileManager: fileManager)
}
}
Expand All @@ -105,7 +105,8 @@ public class ApolloCodegen {
for graphQLObject in ir.schema.referencedTypes.objects {
try autoreleasepool {
try ObjectFileGenerator(
graphqlObject: graphQLObject
graphqlObject: graphQLObject,
config: config
).generate(
forConfig: config,
fileManager: fileManager
Expand Down Expand Up @@ -133,7 +134,7 @@ public class ApolloCodegen {

for graphQLInterface in ir.schema.referencedTypes.interfaces {
try autoreleasepool {
try InterfaceFileGenerator(graphqlInterface: graphQLInterface)
try InterfaceFileGenerator(graphqlInterface: graphQLInterface, config: config)
.generate(forConfig: config, fileManager: fileManager)
}
}
Expand All @@ -142,7 +143,8 @@ public class ApolloCodegen {
try autoreleasepool {
try UnionFileGenerator(
graphqlUnion: graphQLUnion,
schemaName: config.schemaName
schemaName: config.schemaName,
config: config
).generate(
forConfig: config,
fileManager: fileManager
Expand All @@ -163,14 +165,20 @@ public class ApolloCodegen {

for graphQLInputObject in ir.schema.referencedTypes.inputObjects {
try autoreleasepool {
try InputObjectFileGenerator(graphqlInputObject: graphQLInputObject, schema: ir.schema)
.generate(forConfig: config, fileManager: fileManager)
try InputObjectFileGenerator(
graphqlInputObject: graphQLInputObject,
schema: ir.schema,
config: config
).generate(
forConfig: config,
fileManager: fileManager
)
}
}

for graphQLScalar in ir.schema.referencedTypes.customScalars {
try autoreleasepool {
try CustomScalarFileGenerator(graphqlScalar: graphQLScalar)
try CustomScalarFileGenerator(graphqlScalar: graphQLScalar, config: config)
.generate(forConfig: config, fileManager: fileManager)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import Foundation
import ApolloUtils

/// Generates a file containing the Swift representation of a [GraphQL Custom Scalar](https://spec.graphql.org/draft/#sec-Scalars.Custom-Scalars).
struct CustomScalarFileGenerator: FileGenerator {
/// Source GraphQL Custom Scalar..
let graphqlScalar: GraphQLScalarType
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var template: TemplateRenderer {
CustomScalarTemplate(graphqlScalar: graphqlScalar, config: config)
}

var template: TemplateRenderer { CustomScalarTemplate(graphqlScalar: graphqlScalar) }
var target: FileTarget { .customScalar }
var fileName: String { "\(graphqlScalar.name).swift" }
var overwrite: Bool { false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import ApolloUtils
struct EnumFileGenerator: FileGenerator {
/// Source GraphQL enum.
let graphqlEnum: GraphQLEnumType
/// Shared codegen configuration
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var template: TemplateRenderer { EnumTemplate(graphqlEnum: graphqlEnum, config: config) }
var template: TemplateRenderer {
EnumTemplate(graphqlEnum: graphqlEnum, config: config)
}

var target: FileTarget { .enum }
var fileName: String { "\(graphqlEnum.name).swift" }
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import Foundation
import ApolloUtils

/// Generates a file containing the Swift representation of a [GraphQL Fragment](https://spec.graphql.org/draft/#sec-Language.Fragments).
struct FragmentFileGenerator: FileGenerator {
/// Source IR fragment.
let irFragment: IR.NamedFragment
/// Source IR schema.
let schema: IR.Schema
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var template: TemplateRenderer { FragmentTemplate(fragment: irFragment, schema: schema) }
var template: TemplateRenderer { FragmentTemplate(
fragment: irFragment,
schema: schema,
config: config
) }
var target: FileTarget { .fragment(irFragment.definition) }
var fileName: String { "\(irFragment.definition.name).swift" }
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import Foundation
import ApolloUtils

/// Generates a file containing the Swift representation of a [GraphQL Input Object](https://spec.graphql.org/draft/#sec-Input-Objects).
/// Generates a file containing the Swift representation of a
/// [GraphQL Input Object](https://spec.graphql.org/draft/#sec-Input-Objects).
struct InputObjectFileGenerator: FileGenerator {
/// Source GraphQL input object.
let graphqlInputObject: GraphQLInputObjectType

/// IR representation of a GraphQL schema.
let schema: IR.Schema
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var template: TemplateRenderer {
InputObjectTemplate(graphqlInputObject: graphqlInputObject, schema: schema)
InputObjectTemplate(graphqlInputObject: graphqlInputObject, schema: schema, config: config)
}
var target: FileTarget { .inputObject }
var fileName: String { "\(graphqlInputObject.name).swift" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import Foundation
import ApolloUtils

/// Generates a file containing the Swift representation of a [GraphQL Interface](https://spec.graphql.org/draft/#sec-Interfaces).
struct InterfaceFileGenerator: FileGenerator {
/// Source GraphQL interface.
let graphqlInterface: GraphQLInterfaceType
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var template: TemplateRenderer {
InterfaceTemplate(graphqlInterface: graphqlInterface, config: config)
}

var template: TemplateRenderer { InterfaceTemplate(graphqlInterface: graphqlInterface) }
var target: FileTarget { .interface }
var fileName: String { "\(graphqlInterface.name).swift" }
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import Foundation
import ApolloUtils

/// Generates a file containing the Swift representation of a [GraphQL Object](https://spec.graphql.org/draft/#sec-Objects).
struct ObjectFileGenerator: FileGenerator {
/// Source GraphQL object.
let graphqlObject: GraphQLObjectType
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var template: TemplateRenderer {
ObjectTemplate(graphqlObject: graphqlObject)
ObjectTemplate(graphqlObject: graphqlObject, config: config)
}

var target: FileTarget { .object }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import Foundation
import ApolloUtils

/// Generates a file containing the Swift representation of a [GraphQL Union](https://spec.graphql.org/draft/#sec-Unions).
struct UnionFileGenerator: FileGenerator {
/// Source GraphQL union.
let graphqlUnion: GraphQLUnionType
/// Schema name
let schemaName: String
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var template: TemplateRenderer { UnionTemplate(
moduleName: schemaName,
graphqlUnion: graphqlUnion
graphqlUnion: graphqlUnion,
config: config
) }
var target: FileTarget { .union }
var fileName: String { "\(graphqlUnion.name).swift" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import Foundation
import ApolloUtils

/// Provides the format to convert a [GraphQL Custom Scalar](https://spec.graphql.org/draft/#sec-Scalars.Custom-Scalars)
/// into Swift code.
struct CustomScalarTemplate: TemplateRenderer {
/// IR representation of source [GraphQL Custom Scalar](https://spec.graphql.org/draft/#sec-Scalars.Custom-Scalars).
let graphqlScalar: GraphQLScalarType
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var target: TemplateTarget { .schemaFile }

Expand All @@ -24,7 +27,8 @@ struct CustomScalarTemplate: TemplateRenderer {
var template: TemplateString {
TemplateString(
"""
public typealias \(graphqlScalar.name.firstUppercased) = String
\(embeddedAccessControlModifier(config: config))\
typealias \(graphqlScalar.name.firstUppercased) = String
"""
)
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/ApolloCodegenLib/Templates/EnumTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import ApolloUtils
struct EnumTemplate: TemplateRenderer {
/// IR representation of source [GraphQL Enum](https://spec.graphql.org/draft/#sec-Enums).
let graphqlEnum: GraphQLEnumType
/// Shared codegen configuration
var config: ReferenceWrapped<ApolloCodegenConfiguration>
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var target: TemplateTarget { .schemaFile }

var template: TemplateString {
TemplateString(
"""
public enum \(graphqlEnum.name.firstUppercased): String, EnumType {
\(embeddedAccessControlModifier(config: config))\
enum \(graphqlEnum.name.firstUppercased): String, EnumType {
\(graphqlEnum.values.compactMap({
evaluateDeprecation(graphqlEnumValue: $0, config: config)
}), separator: "\n")
Expand Down
6 changes: 5 additions & 1 deletion Sources/ApolloCodegenLib/Templates/FragmentTemplate.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import ApolloUtils

/// Provides the format to convert a [GraphQL Fragment](https://spec.graphql.org/draft/#sec-Language.Fragments)
/// into Swift code.
Expand All @@ -7,13 +8,16 @@ struct FragmentTemplate: TemplateRenderer {
let fragment: IR.NamedFragment
/// IR representation of source GraphQL schema.
let schema: IR.Schema
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var target: TemplateTarget { .operationFile }

var template: TemplateString {
TemplateString(
"""
public struct \(fragment.name.firstUppercased): \(schema.name)\
\(embeddedAccessControlModifier(config: config))\
struct \(fragment.name.firstUppercased): \(schema.name)\
.\(if: isMutable, "Mutable")SelectionSet, Fragment {
public static var fragmentDefinition: StaticString { ""\"
\(fragment.definition.source)
Expand Down
8 changes: 6 additions & 2 deletions Sources/ApolloCodegenLib/Templates/InputObjectTemplate.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import Foundation
import ApolloUtils

/// Provides the format to convert a [GraphQL Input Object](https://spec.graphql.org/draft/#sec-Input-Objects)
/// into Swift code.
struct InputObjectTemplate: TemplateRenderer {
/// IR representation of source [GraphQL Input Object](https://spec.graphql.org/draft/#sec-Input-Objects).
let graphqlInputObject: GraphQLInputObjectType

/// IR representation of a GraphQL schema.
let schema: IR.Schema
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var target: TemplateTarget = .schemaFile

var template: TemplateString {
TemplateString(
"""
public struct \(graphqlInputObject.name.firstUppercased): InputObject {
\(embeddedAccessControlModifier(config: config))\
struct \(graphqlInputObject.name.firstUppercased): InputObject {
public private(set) var data: InputDict

public init(_ data: InputDict) {
Expand Down
6 changes: 5 additions & 1 deletion Sources/ApolloCodegenLib/Templates/InterfaceTemplate.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import Foundation
import ApolloUtils

/// Provides the format to convert a [GraphQL Interface](https://spec.graphql.org/draft/#sec-Interfaces)
/// into Swift code.
struct InterfaceTemplate: TemplateRenderer {
/// IR representation of source [GraphQL Interface](https://spec.graphql.org/draft/#sec-Interfaces).
let graphqlInterface: GraphQLInterfaceType
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

var target: TemplateTarget = .schemaFile

var template: TemplateString {
TemplateString(
"""
public final class \(graphqlInterface.name.firstUppercased): Interface { }
\(embeddedAccessControlModifier(config: config))\
final class \(graphqlInterface.name.firstUppercased): Interface { }
"""
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ struct LocalCacheMutationDefinitionTemplate: OperationTemplateRenderer {
var template: TemplateString {
TemplateString(
"""
public class \(operation.definition.nameWithSuffix.firstUppercased): LocalCacheMutation {
\(embeddedAccessControlModifier(config: config))\
class \(operation.definition.nameWithSuffix.firstUppercased): LocalCacheMutation {
public static let operationType: GraphQLOperationType = .\(operation.definition.operationType.rawValue)

\(section: VariableProperties(operation.definition.variables))
Expand Down
6 changes: 5 additions & 1 deletion Sources/ApolloCodegenLib/Templates/ObjectTemplate.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import Foundation
import ApolloUtils

/// Provides the format to convert a [GraphQL Object](https://spec.graphql.org/draft/#sec-Objects)
/// into Swift code.
struct ObjectTemplate: TemplateRenderer {
/// IR representation of source [GraphQL Object](https://spec.graphql.org/draft/#sec-Objects).
let graphqlObject: GraphQLObjectType
/// Shared codegen configuration.
let config: ReferenceWrapped<ApolloCodegenConfiguration>

let target: TemplateTarget = .schemaFile

var template: TemplateString {
TemplateString(
"""
public final class \(graphqlObject.name.firstUppercased): Object {
\(embeddedAccessControlModifier(config: config))\
final class \(graphqlObject.name.firstUppercased): Object {
override public class var __typename: StaticString { \"\(graphqlObject.name.firstUppercased)\" }

\(section: ImplementedInterfacesTemplate())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ struct OperationDefinitionTemplate: OperationTemplateRenderer {

private func OperationDeclaration(_ operation: CompilationResult.OperationDefinition) -> TemplateString {
return """
public class \(operation.nameWithSuffix.firstUppercased): \(operation.operationType.renderedProtocolName) {
\(embeddedAccessControlModifier(config: config))\
class \(operation.nameWithSuffix.firstUppercased): \(operation.operationType.renderedProtocolName) {
public static let operationName: String = "\(operation.name)"
"""
}
Expand Down
Loading