当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

graphql-advanced-projection

授权协议 MIT License
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 巫马山
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

graphql-advanced-projection

Fully customizable Mongoose/MongoDB projection generator.

Why

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:

  • Separete graphql schema and mongodb projection config. This helps you decouple schema and mongodb into two parts, each of them may change independently. Write graphql in .graphql, write config in javascript or .json.
  • Easy customization. No more gqlField: { type: new GraphQLNonNull(GraphQLInt), projection: 'mongoField' }. Simply gqlField: 'mongoField'.
  • We create resolvers. gqlField: (parent) => parent.mongoField can be automatically generated, even complicated ones like first: (parent) => parent.items.data[0].value.
  • Fully supports interfaces, fragments, and inline fragments. Write typeProj: 'type' and switch (parent.type) in __resolveType.

Installation

$ yarn add graphql-advanced-projection

Usage

For a complete working demo, see the examples folder.

Setup mongoose

const UserSchema = new mongoose.Schema({
  _id: String,
  mongoA: String,
});
const User = mongoose.model('users', UserSchema);

Setup graphql

type Query {
  user(id: ID!): User
}
type User {
  userId: ID
  field1: String
  field2: String
}

Setup graphql-advanced-projection

const { project, resolvers } = gqlProjection({
  User: {
    proj: {
      userId: '_id',
      field1: 'mongoA',
      field2: null,
    },
  },
});

Combine everything together

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 },
});

Run

query {
  user(id: $id) {
    field1
    field2
  }
}
proj = {
  _id: 0,
  mongoA: 1,
}

License

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