Skip to content
/ RCCN Public

A little GraphQL clone for learning purposes

Notifications You must be signed in to change notification settings

shunlog/RCCN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project was made purely for learning purposes.

RCCN

RCCN is a query language for key-value data structures, basically a clone of GraphQL.

Install

Clone this repository and generate the parser with ANTLR (the makefile is in the src directory):

make generate_parser

Then install it with pip from the base directory:

python3 -m pip install -e .

Now you can use the rccn package like this:

from antlr4 import InputStream
from rccn import rccn

def resolver():
    ...

input_stream = InputStream(input_text)
AST = rccn.parse(input_stream)
res = rccn.execute(AST, resolver)
print(res)

Examples

Check out an example of connecting to the PokemonAPI inside the examples/ directory.

The syntax of the language is basically GraphQL but commas are mandatory, therefore whitespace can be and is ignored.

Here's an example query to showcase the syntax :

type Query {
    ability(id: Int): Ability,
    pokemon(id: Int): Pokemon
}

type Ability {
    id: Int,
    name: String,
    is_main_series: Boolean
}

type Pokemon {
    id: Int,
    name: String,
    abilities: [Ability]
}

{
    pokemon (id: 2) {
        name,
        abilities {
            {
                name,
                is_main_series
            }
        }
    }
}

And here's the expected result in JSON for the above query:

{
  "pokemon": {
    "id": 2,
    "name": "ivysaur",
    "abilities": [
      {
        "name": "overgrow",
        "is_main_series": true
      },
      {
        "name": "chlorophyll",
        "is_main_series": true
      }
    ]
  }
}

Features

This language implements a small subset of the features GraphQL has, but nothing it doesn't have:

  • Type definitions
  • Selection sets with fields
  • Field parameters

For contrast, here's some features of GraphQL that RCCN /doesn't/ have:

  • Aliases
  • Fragments
  • Operation Name
  • Variables
  • Directives
  • Inline Fragments
  • Mutations
  • Subscriptions

About

A little GraphQL clone for learning purposes

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published