Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is AST in graphql?

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

like image 658
user2405589 Avatar asked Sep 11 '17 19:09

user2405589


People also ask

What is AST schema?

As Stephen Schneider puts in 'The GraphQL AST— Dawn of a schema', an AST is just a 'fancy way of saying heavily nested objects'. It is a structure that is commonly used in compilers to parse the code we write, converting it into a tree structure that we can traverse programmatically.

What is AST string?

AST stands for Abstract Syntax Tree, which is a potent tool of the Python programming language. It allows us to interact with the Python code itself and can modify it.

What are the three types of operations in GraphQL?

There are three types of operations that GraphQL models: query – a read‐only fetch. mutation – a write followed by a fetch. subscription – a long‐lived request that fetches data in response to source events.

What are GraphQL directives?

Directives are a playground for both GraphQL server implementers and end users alike. GraphQL server implementers can develop features not currently supported by the spec, and users can develop features not yet implemented by the GraphQL server. Directives' unregulated nature is a feature, not a bug.


1 Answers

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

like image 131
Baer Avatar answered Sep 22 '22 10:09

Baer