Skip to content

Commit

Permalink
Updating docs for itemsToGenerate (#3200)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobaFetters authored Aug 21, 2023
1 parent 6d253e2 commit e10dc84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Sources/ApolloCodegenLib/ApolloCodegen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions docs/source/code-generation/run-codegen-in-swift-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e10dc84

Please sign in to comment.