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

Updating Persisted Query Configuration #3175

Merged
merged 25 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
802c9ff
Share logic for creating configuration across commands
AnthonyMDev Aug 3, 2023
c388c1e
Add outputPath arguments to GenerateOperationManifest CLI command
AnthonyMDev Aug 3, 2023
9611aab
Fix error messaging to display correctly
AnthonyMDev Aug 3, 2023
6a9e825
refactor: Fragment types in IR (#3174)
calvincestari Aug 3, 2023
09e52cc
Moving operation manifest config options
BobaFetters Aug 4, 2023
e6c5cc8
Updating CLI commands and documentation
BobaFetters Aug 4, 2023
34a954d
Share logic for creating configuration across commands
AnthonyMDev Aug 3, 2023
173fff2
Add outputPath arguments to GenerateOperationManifest CLI command
AnthonyMDev Aug 3, 2023
372e0ef
Fix error messaging to display correctly
AnthonyMDev Aug 3, 2023
c229fe0
Moving operation manifest config options
BobaFetters Aug 4, 2023
66b71c4
Updating CLI commands and documentation
BobaFetters Aug 4, 2023
97f7a4e
Merge branch 'feature/persisted-query-update' of github.com:apollogra…
BobaFetters Aug 4, 2023
bc9fbfa
Addressing PR feedback
BobaFetters Aug 4, 2023
219b3e9
Renaming option set to `ItemsToGenerate`
BobaFetters Aug 4, 2023
24b8ae0
Minor formatting change
BobaFetters Aug 8, 2023
16f5caa
Renaming .legacyAPQ to .legacy
BobaFetters Aug 8, 2023
a2ca222
Update Sources/ApolloCodegenLib/ApolloCodegenConfiguration.swift
BobaFetters Aug 8, 2023
12f7073
Inline doc changes
BobaFetters Aug 8, 2023
b4baac6
Merge branch 'feature/persisted-query-update' of github.com:apollogra…
BobaFetters Aug 8, 2023
c92ac35
Doc and deprecation updates
BobaFetters Aug 8, 2023
3e6971c
Updating Codegen Config JSON keys
BobaFetters Aug 8, 2023
e70ff0c
Apply suggestions from code review
BobaFetters Aug 9, 2023
bca0fc4
Addressing feedback
BobaFetters Aug 9, 2023
1a3e5ea
Minor adjustment
BobaFetters Aug 9, 2023
cf9543b
Update Sources/CodegenCLI/Commands/GenerateOperationManifest.swift
BobaFetters Aug 9, 2023
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
12 changes: 12 additions & 0 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
54DDB0921EA045870009DD99 /* InMemoryNormalizedCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54DDB0911EA045870009DD99 /* InMemoryNormalizedCache.swift */; };
5AC6CA4322AAF7B200B7C94D /* GraphQLHTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AC6CA4222AAF7B200B7C94D /* GraphQLHTTPMethod.swift */; };
5BB2C0232380836100774170 /* VersionNumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BB2C0222380836100774170 /* VersionNumberTests.swift */; };
6608B3362A7D402B006FB655 /* ApolloCodegenConfiguration+OperationManifestConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6608B3342A7D3FF5006FB655 /* ApolloCodegenConfiguration+OperationManifestConfiguration.swift */; };
662EA65E2A701483008A1931 /* GenerateOperationManifest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 662EA65D2A701483008A1931 /* GenerateOperationManifest.swift */; };
662EA6602A705BD7008A1931 /* GenerateOperationManifestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 662EA65F2A705BD7008A1931 /* GenerateOperationManifestTests.swift */; };
66321AE72A126C4400CC35CB /* IR+Formatting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66321AE62A126C4400CC35CB /* IR+Formatting.swift */; };
Expand Down Expand Up @@ -1140,6 +1141,7 @@
54DDB0911EA045870009DD99 /* InMemoryNormalizedCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InMemoryNormalizedCache.swift; sourceTree = "<group>"; };
5AC6CA4222AAF7B200B7C94D /* GraphQLHTTPMethod.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQLHTTPMethod.swift; sourceTree = "<group>"; };
5BB2C0222380836100774170 /* VersionNumberTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionNumberTests.swift; sourceTree = "<group>"; };
6608B3342A7D3FF5006FB655 /* ApolloCodegenConfiguration+OperationManifestConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ApolloCodegenConfiguration+OperationManifestConfiguration.swift"; sourceTree = "<group>"; };
662EA65D2A701483008A1931 /* GenerateOperationManifest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerateOperationManifest.swift; sourceTree = "<group>"; };
662EA65F2A705BD7008A1931 /* GenerateOperationManifestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerateOperationManifestTests.swift; sourceTree = "<group>"; };
66321AE62A126C4400CC35CB /* IR+Formatting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IR+Formatting.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2206,6 +2208,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
6608B3332A7D3FCB006FB655 /* CodegenConfiguration */ = {
isa = PBXGroup;
children = (
6608B3342A7D3FF5006FB655 /* ApolloCodegenConfiguration+OperationManifestConfiguration.swift */,
);
path = CodegenConfiguration;
sourceTree = "<group>";
};
66B18E862A15366400525DFB /* Network */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2548,6 +2558,7 @@
9BD681332405F6BB000874CB /* Codegen */ = {
isa = PBXGroup;
children = (
6608B3332A7D3FCB006FB655 /* CodegenConfiguration */,
9B7B6F57233C287100F32205 /* ApolloCodegen.swift */,
9B7B6F58233C287100F32205 /* ApolloCodegenConfiguration.swift */,
E674DB40274C0A9B009BB90E /* Glob.swift */,
Expand Down Expand Up @@ -5053,6 +5064,7 @@
E6203342284F1C9600A291D1 /* MockUnionsFileGenerator.swift in Sources */,
DE6D07F927BC3B6D009F5F33 /* GraphQLInputField+Rendered.swift in Sources */,
9F1A966C258F34BB00A06EEB /* GraphQLSchema.swift in Sources */,
6608B3362A7D402B006FB655 /* ApolloCodegenConfiguration+OperationManifestConfiguration.swift in Sources */,
9BE74D3D23FB4A8E006D354F /* FileFinder.swift in Sources */,
E64F7EBC27A11A510059C021 /* GraphQLNamedType+SwiftName.swift in Sources */,
9B7B6F59233C287200F32205 /* ApolloCodegen.swift in Sources */,
Expand Down
114 changes: 61 additions & 53 deletions Sources/ApolloCodegenLib/ApolloCodegen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ public class ApolloCodegen {
}
}
}

public struct ItemsToGenerate: OptionSet {
public var rawValue: Int

public static let code = ItemsToGenerate(rawValue: 1 << 0)
public static let operationManifest = ItemsToGenerate(rawValue: 1 << 1)
public static let all: ItemsToGenerate = [
.code,
.operationManifest
]

public init(rawValue: Int) {
self.rawValue = rawValue
}

}

/// Executes the code generation engine with a specified configuration.
///
Expand All @@ -77,15 +93,17 @@ public class ApolloCodegen {
/// If `nil`, the current working directory of the executing process will be used.
public static func build(
with configuration: ApolloCodegenConfiguration,
withRootURL rootURL: URL? = nil
withRootURL rootURL: URL? = nil,
itemsToGenerate: ItemsToGenerate = [.code]
) throws {
try build(with: configuration, rootURL: rootURL)
try build(with: configuration, rootURL: rootURL, itemsToGenerate: itemsToGenerate)
}

internal static func build(
with configuration: ApolloCodegenConfiguration,
rootURL: URL? = nil,
fileManager: ApolloFileManager = .default
fileManager: ApolloFileManager = .default,
itemsToGenerate: ItemsToGenerate
) throws {

let configContext = ConfigurationContext(
Expand All @@ -103,58 +121,43 @@ public class ApolloCodegen {
try validate(configContext, with: compilationResult)

let ir = IR(compilationResult: compilationResult)

if itemsToGenerate == .operationManifest {
var operationIDsFileGenerator = OperationManifestFileGenerator(config: configContext)

for operation in compilationResult.operations {
autoreleasepool {
let irOperation = ir.build(operation: operation)
operationIDsFileGenerator?.collectOperationIdentifier(irOperation)
}
}

try operationIDsFileGenerator?.generate(fileManager: fileManager)
}

var existingGeneratedFilePaths = configuration.options.pruneGeneratedFiles ?
try findExistingGeneratedFilePaths(
config: configContext,
fileManager: fileManager
) : []

try generateFiles(
compilationResult: compilationResult,
ir: ir,
config: configContext,
fileManager: fileManager
)
if itemsToGenerate.contains(.code) {
var existingGeneratedFilePaths = configuration.options.pruneGeneratedFiles ?
try findExistingGeneratedFilePaths(
config: configContext,
fileManager: fileManager
) : []

if configuration.options.pruneGeneratedFiles {
try deleteExtraneousGeneratedFiles(
from: &existingGeneratedFilePaths,
afterCodeGenerationUsing: fileManager
try generateFiles(
compilationResult: compilationResult,
ir: ir,
config: configContext,
fileManager: fileManager,
itemsToGenerate: itemsToGenerate
)

if configuration.options.pruneGeneratedFiles {
try deleteExtraneousGeneratedFiles(
from: &existingGeneratedFilePaths,
afterCodeGenerationUsing: fileManager
)
}
}
}

public static func generateOperationManifest(
with configuration: ApolloCodegenConfiguration,
withRootURL rootURL: URL? = nil,
fileManager: ApolloFileManager = .default
) throws {
let configContext = ConfigurationContext(
config: configuration,
rootURL: rootURL
)

try validate(configContext)

let compilationResult = try compileGraphQLResult(
configContext,
experimentalFeatures: configuration.experimentalFeatures
)

try validate(configContext, with: compilationResult)

let ir = IR(compilationResult: compilationResult)

var operationIDsFileGenerator = OperationManifestFileGenerator(config: configContext)

for operation in compilationResult.operations {
let irOperation = ir.build(operation: operation)
operationIDsFileGenerator?.collectOperationIdentifier(irOperation)
}

try operationIDsFileGenerator?.generate(fileManager: fileManager)
}

// MARK: Internal

Expand Down Expand Up @@ -411,7 +414,8 @@ public class ApolloCodegen {
compilationResult: CompilationResult,
ir: IR,
config: ConfigurationContext,
fileManager: ApolloFileManager = .default
fileManager: ApolloFileManager = .default,
itemsToGenerate: ItemsToGenerate
) throws {
for fragment in compilationResult.fragments {
try autoreleasepool {
Expand All @@ -431,11 +435,15 @@ public class ApolloCodegen {
try OperationFileGenerator(irOperation: irOperation, config: config)
.generate(forConfig: config, fileManager: fileManager)

operationIDsFileGenerator?.collectOperationIdentifier(irOperation)
if itemsToGenerate.contains(.operationManifest) {
operationIDsFileGenerator?.collectOperationIdentifier(irOperation)
}
}
}

try operationIDsFileGenerator?.generate(fileManager: fileManager)
if itemsToGenerate.contains(.operationManifest) {
try operationIDsFileGenerator?.generate(fileManager: fileManager)
}
operationIDsFileGenerator = nil

for graphQLObject in ir.schema.referencedTypes.objects {
Expand Down
Loading