Skip to content

Commit

Permalink
docs: Updates 1.2.0 migration guide for access modifiers default (#…
Browse files Browse the repository at this point in the history
…3068)
  • Loading branch information
calvincestari authored Jun 9, 2023
1 parent 6510505 commit de57ae4
Showing 1 changed file with 107 additions and 3 deletions.
110 changes: 107 additions & 3 deletions docs/source/migrations/1.2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ This guide describes the process of migrating your code from version 1.0 or 1.1

Though 1.2 is a minor version bump, a critical problem was addressed in this version that requires a small breaking change during the upgrade. While we strive to make the upgrade path for minor versions seamless, this issue could not be reasonably resolved without requiring this migration.

**For most users, this migration will only require a single change to your `SchemaConfiguration.swift` file.**

## Cache Key Configuration API

The API for [configuring custom cache keys](../caching/cache-key-resolution) has had a minor change in this version. The signature of the `cacheKeyInfo(for:object:)` function, defined in your generated `SchemaConfiguration.swift` file, has been modified.
Expand Down Expand Up @@ -139,4 +137,110 @@ case Objects.User:
return try? CacheKeyInfo(
jsonValue: object["info"]?["emailAddresses"]?[0]
)
```
```
## Swift Access Modifiers

`1.2.0` introduces new codegen configuration parameters that allow you to specify the access control of the generated Swift types. When using a module type of [`embeddedInTarget`](../code-generation/codegen-configuration#module-type) or operation output types of [`relative` or `absolute`](../code-generation/codegen-configuration#operations) you can choose to have the generated Swift types be accessible with `public` or `internal` access.

**You do not need to add these options to your codegen configuration but the default used when the option is not specified is different from previous Apollo iOS versions.**

Before `1.2.0` all Swift types were generated with `public` access, the default for the new configuration option is `internal`.

This means that where you might have been using publicly available Swift types before you might now have compiler errors where those types are no longer accessible. To resolve this you will need to add the configuration option to your codegen configuration specifying the `public` access modifier.

**You may need to make manual changes to the schema configuration and custom scalar files because these files are not regenerated if they already exist. The alternative to manually updating them is to remove those files, run code generation, and then re-add any custom logic you may have had in the pre-existing custom scalar files.**

### Example

#### Module type

<MultiCodeBlock>

```json title="CLI Configuration JSON"
"output": {
"schemaTypes": {
"moduleType": {
"embeddedInTarget": {
"name": "MyApplicationTarget",
"accessModifier": "public"
}
},
"path": "./generated/schema/"
}
}
```

```swift title="Swift Codegen Setup"
let configuration = ApolloCodegenConfiguration(
// Other properties not shown
output: ApolloCodegenConfiguration.FileOutput(
schemaTypes: ApolloCodegenConfiguration.SchemaTypesFileOutput(
path: "./generated/schema/",
moduleType: .embeddedInTarget(name: "MyApplicationTarget", accessModifier: .public)
)
...
)
)
```

</MultiCodeBlock>

#### Operations - `relative`

<MultiCodeBlock>

```json title="CLI Configuration JSON"
"output": {
"operations" : {
"relative" : {
"subpath": "Generated",
"accessModifier": "public"
}
}
}
```

```swift title="Swift Codegen Setup"
let configuration = ApolloCodegenConfiguration(
// Other properties not shown
output: ApolloCodegenConfiguration.FileOutput(
operations: .relative(
subpath: "generated",
accessModifier: .public
)
...
)
)
```

</MultiCodeBlock>

#### Operations - `absolute`

<MultiCodeBlock>

```json title="CLI Configuration JSON"
"output": {
"operations" : {
"absolute" : {
"path": "Generated",
"accessModifier": "public"
}
}
}
```

```swift title="Swift Codegen Setup"
let configuration = ApolloCodegenConfiguration(
// Other properties not shown
output: ApolloCodegenConfiguration.FileOutput(
operations: .absolute(
path: "generated",
accessModifier: .public
)
...
)
)
```

</MultiCodeBlock>

0 comments on commit de57ae4

Please sign in to comment.