dinoql 支持自定义resovler了
dinoql 当前版本0.4.0 支持自定义reovler 了,使用也比较简单
环境准备
- 初始化
yarn init -y
- 添加依赖
yarn add dinoql graphql-tag
- package.json npm script 添加
当前已经解决了node 环境运行的问题了,所以不需要添加多少东西了
{
"name": "dinoql-app",
"version": "1.0.0",
"main": "app.js",
"license": "MIT",
"dependencies": {
"dinoql": "^0.4.0",
"graphql-tag": "^2.10.1"
},
"scripts": {
"s":"node app"
}
}
- 代码
app.js
const dinoql= require("dinoql")
const gql = require("graphql-tag");
const users = {
users: [
{
name:"dalong",
age:33,
tag:"local"
},
{
name:"system",
age:32,
tag:"system"
}
]
}
const query = gql`
query Userinfo {
users(mergeTag: "--dalongdemo--") {
name
age
}
}
`
const mergeTag = (list, right) => {
return list.map(item => ({ ...item, age: item.tag + right }));
};
dinoql.addResolvers(({ mergeTag }));
const queryResult = dinoql(users)(query)
console.log(JSON.stringify(queryResult))
测试
- 运行
yarn s
- 结果
yarn run v1.13.0
$ node app
{"users":[{"name":"dalong","age":"local--dalongdemo--"},{"name":"system","age":"system--dalongdemo--"}]}
说明
dinoql 对于web端应用的开发是一个不错的数据处理选择,同时也可以在node 端云运行