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/
Slide 6
Slide 6 text
*.graphql
Query definition file
Slide 7
Slide 7 text
schema.json
*.graphql
ʴ
Slide 8
Slide 8 text
schema.json
*.graphql
Token AST IR
→
Slide 9
Slide 9 text
Lexer
.graphql to Tokens
Slide 10
Slide 10 text
User.graphql
Slide 11
Slide 11 text
User.graphql
Tokens
query
User
(
$
id
email
@
include
…
AddressFragment
Debug
:
response
~~~~~
~~~~~
~~~~~
~~~~~
~~~~~
~~~~~
~~~~~
~~~~~
Slide 12
Slide 12 text
query User
(
$
@
…
AddressFragment
NAME
Kind Value
undefined
undefined
undefined
undefined
COMMENT Debug
Ignoring on parsing phase
name
: undefined
Slide 13
Slide 13 text
`#` itself is not a token kind.
-> Other ways to comment out, like `/**/`?
Slide 14
Slide 14 text
https://github.com/graphql/graphql-js/blob/master/src/language/lexer.js#L187
https://github.com/graphql/graphql-spec/issues/276
Reading implementation of lexer, it seems only `#` indicates comment.
Slide 15
Slide 15 text
Parser
Tokens to AST
Slide 16
Slide 16 text
query
User
AddressFragment
NAME
NAME
NAME
Operation definition
name
NAME
Tokens Semantics
Operation name
field name
Fragment name
Slide 17
Slide 17 text
(
$
@
…
Beginning of definition of arguments, etc.
Variable
Directive
Fragment/Inline Fragment Spread
Tokens
: Argument, Alias, etc.
Semantics
Slide 18
Slide 18 text
NAME Token: Semantics depends on syntax and value.
Punctuator Token: Semantics is fixed or depends on syntax
( $ : @
Slide 19
Slide 19 text
No content
Slide 20
Slide 20 text
Document
Hoge parsing operation
function parseHoge is defined in graphql/language/parser.js
=
OperationDefinition
OperationType Name VariableDefinitions
VariableDefinition
SelectionSet
VariableDefinition
Recursive Descent Parsing
Slide 21
Slide 21 text
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 ……
VariableDefinition
Type
Variable
Name
value: string
Name
value: string
Slide 28
Slide 28 text
Type
Variable
Name
value: id
Name
value: Int!
VariableDefinitions
VariableDefinition VariableDefinition
Type
Variable
Name
value: withEmail
Name
value: Boolean!
Slide 29
Slide 29 text
VariableDefinitions
VariableDefinition VariableDefinition
+ schema.json
GraphQLType
GraphQLType
Type
Variable
Name
value: id
Name
value: Int!
Type
Variable
Name
value: withEmail
Name
value: Boolean!
Slide 30
Slide 30 text
IR
Slide 31
Slide 31 text
IR
CompilerContext LegacyCompilerContext
Slide 32
Slide 32 text
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.