32
votes

What is AST in graphql ? I am using graphql-js. How does it help with anything?

Nothing in any documentation seems to explain what AST is

1
AST stands for Abstract Syntax Tree in web technologies not only in graphql. You can read it up here: en.wikipedia.org/wiki/Abstract_syntax_treeAdemola Adegbuyi
Actually not only in web technologies, AST is a broader term in computer science.ozanmuyes

1 Answers

48
votes

GraphQL is two things:

  1. A query language
  2. A Type System

When a GraphQL server receives a query to process it generally comes in as a single String. This string must be split into meaningful sub-strings (tokenization) and parsed into a representation that the machine understands. This representation is called an abstract syntax tree, or AST.

When GraphQL Processes the query, it walks the tree executing each part against the schema.

Converting raw strings to an AST is the first step of every compiler from C++ to Chrome's JavaScript's VM to Babel.

As for what GraphQL does and how it helps, here is a video that may explain it in a bit more detail. https://www.youtube.com/watch?v=PmWho45WmQY