Fully customizable Mongoose/MongoDB projection generator.
We already have graphql-projection, graphql-mongodb-projection, and graphql-db-projection.But graphql-advanced-projection
is different from all of them above in the following ways:
.graphql
, write config in javascript or .json
.gqlField: { type: new GraphQLNonNull(GraphQLInt), projection: 'mongoField' }
. Simply gqlField: 'mongoField'
.gqlField: (parent) => parent.mongoField
can be automatically generated, even complicated ones like first: (parent) => parent.items.data[0].value
.typeProj: 'type'
and switch (parent.type)
in __resolveType
.$ yarn add graphql-advanced-projection
For a complete working demo, see the
examples
folder.
mongoose
const UserSchema = new mongoose.Schema({
_id: String,
mongoA: String,
});
const User = mongoose.model('users', UserSchema);
graphql
type Query {
user(id: ID!): User
}
type User {
userId: ID
field1: String
field2: String
}
graphql-advanced-projection
const { project, resolvers } = gqlProjection({
User: {
proj: {
userId: '_id',
field1: 'mongoA',
field2: null,
},
},
});
module.exports = makeExecutableSchema({
typeDefs,
resolvers: _.merge(resolvers, {
Query: {
async user(parent, args, context, info) {
const proj = project(info);
const result = await User.findById(args.id, proj);
return result.toObject();
},
},
User: {
field2: () => 'Hello World',
},
}),
resolverValidationOptions: { requireResolversForResolveType: false },
});
query {
user(id: $id) {
field1
field2
}
}
proj = {
_id: 0,
mongoA: 1,
}
MIT
Advanced features aims to help developer implement interactive applications more effectively. function chain switchCountry
描述 (Description) data-top-anchor = "idOfSomething", data-btm-anchor = "idOfSomething:[top/bottom]" ,或者设置像素数data-top-anchor = "150"用于将图像或粘性内容设置为一个特定的高度。 例子 (Example) 以下示例演示了在Foundation中使用toggler插件 - <!
链接 系统启动 参数&配置 参考参数 安装Intel RealSense R200的驱动 切换状态估计器 外部模块 STM32 Bootloader
Topics: Focus handling system Slivers Gestures
互联网 Java 工程师进阶知识完全扫盲 本项目大部分内容来自中华石杉,版权归作者所有,内容涵盖高并发、分布式、高可用、微服务、海量数据处理等领域知识。我对这部分知识做了一个系统的整理,方便学习查阅。 本项目已开通 Discussions 功能。学习之前,先来看看 Discussions 讨论区的技术面试官是怎么说的吧。本项目欢迎各位开发者朋友到 Discussions 讨论区分享自己的一些想法和
Advanced Node.js For help, ask in #questions at slack.jscomplete.com