Skip to content

Generated types import the entire Apollo runtime #1047

@gsabran

Description

@gsabran

The generated types implement protocols defined in Apollo, such as GraphQLQuery. For this, they need to import Apollo where most of the code is about cache management and decoding (see example).
For most apps this is fine, but in the context of a very large app where there is a focus on reducing dependencies, this is problematic and there is a need to reduce the dependencies that each generate type creates.

Ideally, things would look like (scroll right!)

               Apollo                  |                Consumer application
                                       |
                                       |
----------------------------------             ----------------------------------------
|          ApolloTypes           |             |             Type Module A            |
|                                |    <---     |                                      |
| protocol GraphQLQuery { ... }  |             | import ApolloTypes                   |
|________________________________|             | class MyQuery: GraphQLQuery { ... }  |      ------------------------------
                                               |______________________________________| <--- |      Feature Module A      |
                ^                                                                            |                            |
                |                                                                            | import TypeModuleA         |
                                                                                             | import Networking          | 
----------------------------------             ----------------------------------            |                            |
|            Apollo              |             |        Networking Module       |     <---   | network.send(MyQuery())    |
|                                |             |                                |            |____________________________|
| ApolloClient etc               |    <---     | Apollo                         |
| extension GraphQLQuery { ... } |             | ...                            |
|________________________________|             |________________________________|

where a type module would not depend on the entirety of Apollo

I think this is the exhaustive list of protocols required by the generated types

  • GraphQLBooleanCondition
  • GraphQLField
  • GraphQLFragment
  • GraphQLFragmentSpread
  • GraphQLID
  • GraphQLInputValue
  • GraphQLMap
  • GraphQLMapConvertible
  • GraphQLMutation
  • GraphQLOperation
  • GraphQLOperationType
  • GraphQLOutputType
  • GraphQLQuery
  • GraphQLSelection
  • GraphQLSelectionSet
  • GraphQLSubscription
  • GraphQLTypeCase
  • GraphQLTypeCondition
  • GraphQLVariable
  • JSONDecodable
  • JSONEncodable
  • JSONDecodingError
  • ResultMap

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenIssues related to or arising from code generationdiscussionRequests for comment or other discussions

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions