From e10dc84167b7edd4511d94ae7bbfafb65dca074b Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Mon, 21 Aug 2023 13:15:25 -0400 Subject: [PATCH] Updating docs for `itemsToGenerate` (#3200) --- Sources/ApolloCodegenLib/ApolloCodegen.swift | 9 +++++++++ .../source/code-generation/run-codegen-in-swift-code.mdx | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Sources/ApolloCodegenLib/ApolloCodegen.swift b/Sources/ApolloCodegenLib/ApolloCodegen.swift index 2b6cd3fa45..4cc01ccaaf 100644 --- a/Sources/ApolloCodegenLib/ApolloCodegen.swift +++ b/Sources/ApolloCodegenLib/ApolloCodegen.swift @@ -68,11 +68,18 @@ public class ApolloCodegen { } } + /// OptionSet used to configure what items should be generated during code generation. public struct ItemsToGenerate: OptionSet { public var rawValue: Int + /// Only generate your code (Operations, Fragments, Enums, etc), this option maintains the codegen functionality + /// from before this option set was created. public static let code = ItemsToGenerate(rawValue: 1 << 0) + + /// Only generate the operation manifest used for persisted queries and automatic persisted queries. public static let operationManifest = ItemsToGenerate(rawValue: 1 << 1) + + /// Generate all available items during code generation. public static let all: ItemsToGenerate = [ .code, .operationManifest @@ -91,6 +98,8 @@ public class ApolloCodegen { /// during code generation. /// - rootURL: The root `URL` to resolve relative `URL`s in the configuration's paths against. /// If `nil`, the current working directory of the executing process will be used. + /// - itemsToGenerate: Uses the `ItemsToGenerate` option set to determine what items should be generated during codegen. + /// By default this will use [.code] which maintains how codegen functioned prior to these options being added. public static func build( with configuration: ApolloCodegenConfiguration, withRootURL rootURL: URL? = nil, diff --git a/docs/source/code-generation/run-codegen-in-swift-code.mdx b/docs/source/code-generation/run-codegen-in-swift-code.mdx index db54797a2d..115788180c 100644 --- a/docs/source/code-generation/run-codegen-in-swift-code.mdx +++ b/docs/source/code-generation/run-codegen-in-swift-code.mdx @@ -31,14 +31,14 @@ Once you've installed the `ApolloCodegenLib` dependency in your project, you can - [Installing `ApolloCodegenLib`](#installing-apollocodegenlib) - [Usage](#usage) - - [Running code generation](#running-code-generation) - - [Downloading a schema](#downloading-a-schema) + - [Running code generation](#running-code-generation) + - [Downloading a schema](#downloading-a-schema) ### Running code generation -To configure and run code generation using `ApolloCodegenLib`, create an [`ApolloCodegenConfiguration`](https://www.apollographql.com/docs/ios/docc/documentation/apollocodegenlib/apollocodegenconfiguration), then pass it to `ApolloCodegen.build(with configuration:withRootURL:)` function. +To configure and run code generation using `ApolloCodegenLib`, create an [`ApolloCodegenConfiguration`](https://www.apollographql.com/docs/ios/docc/documentation/apollocodegenlib/apollocodegenconfiguration), then pass it to `ApolloCodegen.build(with configuration:withRootURL:itemsToGenerate:)` function. -By default, the Code Generation Engine will resolve all file paths in your `ApolloCodegenConfiguration` relative to the current working directory. The `rootURL` parameter can be used to provide a local file path URL of the root of the project that you want to run code generation on. This will resolve file paths in your configuration relative to the provided `rootURL`. +By default, the Code Generation Engine will resolve all file paths in your `ApolloCodegenConfiguration` relative to the current working directory. The `rootURL` parameter can be used to provide a local file path URL of the root of the project that you want to run code generation on. This will resolve file paths in your configuration relative to the provided `rootURL`. The [`itemsToGenerate`](https://www.apollographql.com/docs/ios/docc/documentation/apollocodegenlib/apollocodegen/itemsToGenerate) parameter allows you to customize what items will be generated. If you don't provide options this will default to `[.code]` which will just generate code files in the same way code generation worked prior to this option set being added in version 1.4.0. ```swift import ApolloCodegenLib