New
- Add the
selectionSetDebugDescriptionConformancecodegen option (#1108): Every generated selection set conformed toCustomDebugStringConvertiblethroughApolloAPI.SelectionSet, which adds a protocol conformance record to your binary for each generated type. For large schemas, these records can increase app launch time.ApolloAPI.SelectionSetno longer inheritsCustomDebugStringConvertible. The generated schema-level selection set protocols now declare the conformance instead, controlled by the new option:include(the default, matching previous behavior),exclude,debugOnly, or a customcompilationCondition.debugDescriptionremains available on every selection set. Without the conformance,String(describing:),debugPrint(_:), and the LLDBpocommand use the default reflection-based output. Regenerate your code after upgrading to keep the conformance. Thank you to @bdunay3 for the contribution.
Improvement
- Update the codegen frontend to
graphql17.1.0 (#1110): The bundled GraphQL compiler now uses graphql-js 17.1.0 and is built with rollup 4.68.8 and@rollup/plugin-terser1.0.2. Generated code is unchanged.
Fixed
- Generate the same test mocks on every codegen run (#1092): Codegen builds operations and fragments concurrently. When two of them selected different schema fields under the same response key, usually through aliases, the test mock property type depended on which one finished first, so generated mocks could change between runs with no changes to the schema or operations. The property type is now derived from every field selected with that key, so it accepts a value that's valid for every operation selecting it. Fields that differ only in nullability use the nullable type, conflicting object, interface, or union types accept any mock, and other incompatible types use the new
AnyFieldValuetype inApolloTestSupport. A field selected through an interface now uses the object's own field type, which can be stricter than the interface's. See Setting properties on test mocks. Thank you to @3redrubies for the contribution.- Source changes to generated test mocks: Regenerated mocks can change in two cases. A key selected with conflicting types now has a getter of type
InterfaceorAnyHashable?, list elements that may now be optional, and a parameter that defaults tonil. A field selected through an interface whose object declares a stricter type now uses that type: for example,title: String? = nilbecomestitle: String = "", andfriend: (any AnyMock)?becomesfriend: Mock<Dog>?. Update test code that reads these properties or passes values to them.
- Source changes to generated test mocks: Regenerated mocks can change in two cases. A key selected with conflicting types now has a getter of type
- Resolve field policies when the root record is missing from the cache (#1109): A cache read failed before any field policy ran when the store had no
QUERY_ROOTrecord, so a root field missed even when its field policy named a cached record. A missingQUERY_ROOT,MUTATION_ROOT, orSUBSCRIPTION_ROOTrecord now loads as an empty record, so root fields fall through to their field policies. Any other missing record is still a cache miss. Fixes #3661. Thank you to @drewmclean for the contribution.