Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Apollo_Code_Generation [en]

October 09, 2019

Apollo_Code_Generation [en]


October 09, 2019

More Decks by YuyaHorita

Other Decks in Programming


  1. Introduction Yuya Horita iOS Engineer @CyberAgent, 2017/4 ~ 2019/5 Software

    Engineer @M3, 2019/5 ~ GitHub: https://github.com/horita-yuya Twitter: https://twitter.com/horita_yuya Medium: https://medium.com/@yuyaHorita
  2. schema.json File contains the results of an introspection query, or

    query information > Conventionally this file is called schema.json Reference: https://www.apollographql.com/docs/ios/downloading-schema/
  3. User.graphql Tokens query User ( $ id email @ include

    … AddressFragment Debug : response ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~
  4. query User ( $ @ … AddressFragment NAME Kind Value

    undefined undefined undefined undefined COMMENT Debug Ignoring on parsing phase name : undefined
  5. `#` itself is not a token kind. -> Other ways

    to comment out, like `/**/`?
  6. query User AddressFragment NAME NAME NAME Operation definition name NAME

    Tokens Semantics Operation name field name Fragment name
  7. ( $ @ … Beginning of definition of arguments, etc.

    Variable Directive Fragment/Inline Fragment Spread Tokens : Argument, Alias, etc. Semantics
  8. NAME Token: Semantics depends on syntax and value. Punctuator Token:

    Semantics is fixed or depends on syntax ( $ : @
  9. Document Hoge parsing operation function parseHoge is defined in graphql/language/parser.js

    = OperationDefinition OperationType Name VariableDefinitions VariableDefinition SelectionSet VariableDefinition Recursive Descent Parsing
  10. Tokens Rules + Starts with operation definition keyword `query`. The

    next `User` is operation name. If `(` exists in just after `User`, variable definitions starts. It will end with `)`. Next `{` means the beginning of definition of SelectionSet ……
  11. Type Variable Name value: id Name value: Int! VariableDefinitions VariableDefinition

    VariableDefinition Type Variable Name value: withEmail Name value: Boolean!
  12. VariableDefinitions VariableDefinition VariableDefinition + schema.json GraphQLType GraphQLType Type Variable Name

    value: id Name value: Int! Type Variable Name value: withEmail Name value: Boolean!
  13. IR

  14. Summary 1. AST from *.graphql. 2. IR from ast and

    schema.json. 3. .swift, .ts, .scala from IR 4. It seems .kt doesn’t use apollo-tooling. All implementations are in apollo-android.