| ... | ... | @@ -31,4 +31,13 @@ |
|
|
|
* Context - 最重要的对象之一,一个request在服务器的生命周期会贯穿着一个Context object,里面的一些属性非常用有
|
|
|
|
1. me - Me的实例,包含当前用户的信息
|
|
|
|
2. startTime - 这个context被初始化的时间
|
|
|
|
3. query - graphql的query信息 |
|
|
\ No newline at end of file |
|
|
|
3. query/mutation/variables 等一些和graphql相关的信息,一般不用管
|
|
|
|
4. error - Error若出错,可以将错误设置到Context里,不过一般的处理方式是直接throw Error
|
|
|
|
* isAdmin(me: Me) - 函数,返回true如果当前用户是超级管理员
|
|
|
|
* initContext(query: string, variables: string, mutation: string, operationName: string, me: Me) - 函数,用于初始化一个Context,主要用户类似cron job这种不是从request初始化的context
|
|
|
|
* Query - 代表一个查询接口,包含四个fields
|
|
|
|
1. args - Object,所有Query一定要包含args,里面对应mongo的查询条件,比如 {_id: 'abcfd'}
|
|
|
|
2. limit - 分页时用,未提供的时候默认页面大小为100
|
|
|
|
3. sort - 排序
|
|
|
|
4. skip - 忽略多少条记录,用于mongo数据库查询分页时,返回指定页的数据时使用,比如页面大小limit=10,需要第三页时skip为20
|
|
|
|
* isLogin(me: Me) - 当前用户是否已经登录 |