# 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 这是一个 类 graphql 语法 + 简单sql语法的解析器+代码生成器 语法解析器使用PEGjs生成 代码生成器支持生成 - mapper - resultMapper - model - select ## 在线体验 [http://youngboyvip.gitee.io/youngboy/mybatis.html](http://youngboyvip.gitee.io/youngboy/mybatis.html) ## nodejs测试脚本 ``` node graphql.js class.gql ``` ## 语法示例 语法规则 [] 代表可选 ``` select mapper接口方法名(type:接收数据的全限定类名,fetch:返回对象还是集合可选list或obj){ 表别名.字段名[:字段别名和sql里as一致] [数据类型同java里类型一致], ... 字段名.config(type:接收数据的全限定类名,fetch:返回对象还是集合可选list或obj){ 表别名.字段名[:字段别名和sql里as一致] [数据类型同java里类型一致], ... } } from(表或子查询 join 表或子查询 同sql语法) ``` ```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 ``` ## 解析结果 ```json { "call": "findByRootIdOrClassId", "parameters": [ { "name": "type", "value": "vip.youngboy.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": "vip.youngboy.model.TplModuleInfo" }, { "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": "subList", "calls": [ { "call": "config", "parameters": [ { "name": "type", "value": "vip.youngboy.model.TplModuleItem" }, { "name": "fetch", "value": "list" } ] } ], "properties": { "properties": [ { "name": "id", "alias": "d", "type": "Long", "jname": null }, { "name": "name", "alias": "d", "type": "String", "jname": null } ] } } ] } } ], "querybody": "tpl_class_info b\n join tpl_class_rel c ON b.id = c.classId\n join tpl_module_info a ON a.id = c.modId join tpl_module_item d.mid=c.id" } ```