Open
Description
Use case
We're working on updating our tests to use the generated ApolloTestSupport.Mock
initializers. We've noticed that it's fairly difficult to create the Mocks
and response types.
- When typing
.from(...)
, autocomplete shows everyMock
init that's accessible. - If a
.from(...)
is passed an incorrectMock
type, it fails at runtime.- The runtime error message doesn't help determine the correct type.
ApolloTestSupport/TestMock.swift:131: Fatal error: 'try!' expression unexpectedly raised an error: Apollo.GraphQLExecutionError(path: refreshToken, underlying: ApolloAPI.JSONDecodingError.wrongType)
- Since the type name is not always the same as the field name, the only reliable way we've found to determine the type of
Mock
to create it by looking at the selection set's__parentType
property in the generated code.
Describe the solution you'd like
Ideally there'd be more type information in the MockObject
and selection sets. The the compiler could tell whether .from(...)
is being passed a mock that is valid for the selection set and resolve the difficulties from above.
- Autocomplete would only show the mock inits that are valid for the type
.from(...)
is being called on. - It would replace a runtime error with a compile time error, which is always a better developer experience.
- This would be less necessary if the autocomplete didn't show invalid inits.