# graphqljs **Repository Path**: youngboyvip/graphqljs ## Basic Information - **Project Name**: graphqljs - **Description**: mybatis 一对多代码生成 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 0 - **Created**: 2020-11-19 - **Last Updated**: 2022-07-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # GraphQL JS [中文文档](README_zh.md) test script ``` node graphql.js class.gql ``` A simple [GraphQL](https://gist.github.com/wincent/598fa75e22bdfa44cf470) parser written in JavaScript. ## 在线demo [http://youngboyvip.gitee.io/youngboy/mybatis.html](http://youngboyvip.gitee.io/youngboy/mybatis.html) ## Usage ### Parser API The parser is generated by PEGjs, I'd recommend reading their [docs](http://pegjs.org/documentation#using-the-parser) on parser usage. But it's pretty simple: ```js var parser = require('graphql'); var query = ` select findByRootIdOrClassId(type:"vip.youngboy.model.TplClass") { b.id Long, b.class_name:className String, b.p_name:pName String, c.rootId Long, components.config(type:"vip.youngboy.model.TplModuleInfo",fetch:"list"){ a.id Long, a.component:component String, a.name String, subList.config(type:"vip.youngboy.model.TplModuleItem",fetch:"list"){ d.id Long, d.name String } } } from tpl_class_info b join tpl_class_rel c ON b.id = c.classId join tpl_module_info a ON a.id = c.modId join tpl_module_item d.mid=c.id `; var ast = parser.parse(query); // ast is a plain JS object ``` #### Example output Going off the above query, the return AST would look like this: ```json { "call": "findByRootIdOrClassId", "parameters": [ { "name": "type", "value": "com.fawkes.yhsw.common.model.TplClass" } ], "root": true, "properties": [ { "name": "id", "alias": "b", "type": "Long", "jname": null }, { "name": "class_name", "alias": "b", "type": "String", "jname": "className" }, { "name": "p_name", "alias": "b", "type": "String", "jname": "pName" }, { "name": "rootId", "alias": "c", "type": "Long", "jname": null }, { "name": "components", "calls": [ { "call": "config", "parameters": [ { "name": "type", "value": "com.fawkes.yhsw.common.model.TemplateModuleInfo" }, { "name": "fetch", "value": "list" } ] } ], "properties": { "properties": [ { "name": "id", "alias": "a", "type": "Long", "jname": null }, { "name": "component", "alias": "a", "type": "String", "jname": "component" }, { "name": "name", "alias": "a", "type": "String", "jname": null }, { "name": "page_type", "alias": "a", "type": "String", "jname": "pageType" }, { "name": "thumbnail", "alias": "a", "type": "String", "jname": null }, { "name": "range_index", "alias": "a", "type": "Integer", "jname": "rangeIndex" } ] } } ], "querybody": "tpl_class_info b\r\n JOIN tpl_class_rel c ON b.id = c.classId\r\n JOIN template_module_info a ON a.id = c.modId\r\n" } ``` ### Demo After cloning, install deps with `npm install`. You can re-build the parser by running `npm run build` Or see a demo of its output by running `npm run demo`, this runs the parser over `./examples/friends.gql` and dumps the parsed object to the console.