vulcanjs schemas collections

news/2024/7/4 9:57:58

一张参考图

说明

从上图我们可以方便的看出schmea 能做的事情

  • Generate a GraphQL equivalent of your schema to control your GraphQL API.(生成 graphql api)
  • Control permissions for accessing and modifying data.(访问控制)
  • Generate forms on the client.(client 以及表单生成)
  • Validate form contents on submission.(数据校验)
  • Auto-generate paginated, searchable datatables.(自动生成分页,查询)
  • Auto-generate smart cards for displaying individual documents.(智能卡生成)
  • Add callbacks on document insert or edit.(数据添加,编辑时候的回掉)

参考例子

  • schema

    类似graphql-yogo 以及graphql-js 的schema 定义

const schema = {
  // default properties

  _id: {
    type: String,
    optional: true,
    canRead: ["guests"]
  },
  createdAt: {
    type: Date,
    optional: true,
    canRead: ["guests"],
    onCreate: ({ newDocument, currentUser }) => {
      return new Date();
    }
  },
  userId: {
    type: String,
    optional: true,
    canRead: ["guests"],
    resolveAs: {
      fieldName: "user",
      type: "User",
      resolver: (movie, args, context) => {
        return context.Users.findOne(
          { _id: movie.userId },
          {
            fields: context.Users.getViewableFields(
              context.currentUser,
              context.Users
            )
          }
        );
      },
      addOriginalField: true
    }
  },

  // custom properties

  name: {
    label: "Name",
    type: String,
    optional: true,
    canRead: ["guests"],
    canCreate: ["members"],
    canUpdate: ["members"]
  },
  year: {
    label: "Year",
    type: String,
    optional: true,
    canRead: ["guests"],
    canCreate: ["members"],
    canUpdate: ["members"]
  },
  review: {
    label: "Review",
    type: String,
    optional: true,
    control: "textarea",
    canRead: ["guests"],
    canCreate: ["members"],
    canUpdate: ["members"]
  }
};
  • 创建collection

    实际上上就是graphql api schema 定义以及解析处理

const Movies = createCollection({
  typeName: "Movie",
  schema,
  resolvers,
  mutations
});

参考资料

http://docs.vulcanjs.org/schemas.html

 
 
 
 

http://www.niftyadmin.cn/n/4261157.html

相关文章

loadrunner测试mysql数据库_Loadrunner测试mysql数据库

loadrunner可以利用mysql lib库,通过引用外部DLL,模拟mysql客户端连接数据库进行增删改查的操作进行测试。下面主要介绍如何利用mysql lib库连接mysql数据库进行性能测试。一、准备工作1. 下载 MySQL LoadRunner libraries。2. MySQL LoadRunner librari…

Spring Cloud Gateway全局过滤器GlobalFilter初探

定义 在【spring cloud gateway】的官方文档中,全局过滤器GlobalFilter接口是这样定义的: The GlobalFilter interface has the same signature as GatewayFilter. These are special filters that are conditionally applied to all routes. (This inte…

主引导分区VS超级块

硬盘里分为两个区域,一个是实际文件数据文件放置的地方,一个是放置关于整个硬盘的信息区,我们称这个为主引导分区(MBR,MASTER BOOT RECORDER)。MBR里记录了两个重要的信息,分别是:引导程序与磁盘分区表。由于MBR仅能保存4个分区的数据记录,如…

mysql数据库在什么程序操作_MYSQL数据库基本操作

一,MYSQL数据库的简介1,数据库的概念数据库就是以一定格式进行组织的数据的集合。通俗来看数据库就是用户计算机上 一些具有特殊格式的数据文件的集合。2,相比于普通文件,数据库的特点1)持久化存储,2)读写速度极高&…

FreeBSD内核编译注意事项[zt]

http://hi.baidu.com/iamacnhero/blog/item/54c272032cab60ef08fa935f.html在核心设定中加入 options QUOTA 这一行,启用磁盘配额。使核心支持 NAT 及防火墙功能:# 防火墙options IPFIREWALL# 支援 NAToptions IPDIVERT# 下面这一行是预设允许所有封包通…

我发起了一个 支持 PostgreSql 的 外围设施 的 .Net 开源项目

目标 : 让 PostgreSql 成为 通用的 跨平台 的 数据库 , 成为 开发者 喜爱 的 利器 。 要做的事 , 当然 , PostgreSql 本身现在不用我们去做什么 。 一个 数据库 要成为 开发者喜爱的 流行的 普遍使用的 数据库 , 需要…

c# mysql 参数使用实例_C#操作MySQL数据库的简单例子

本示例演示了用C#操作MySQL的方法,提供了三个可重用的类MySqlDBUtil,MySqlPageUtil,Page。本示例由 C#操作Access数据库的简单例子修改而来。1.首先下载MySQL数据库的.NET驱动http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-5.0.8.1-noinst…

How To Determinate If An EMCPOWER Partition Is Valid For ASMLIB

If you are trying to create an ASMLIB disk using an emcpower# partition and you get the next error: ASMdisk:asmtool:Device"/dev/emcpowera11"isnotapartition[FAILED] Then you will need to determinate if the emcpower# partition is valid. 解决步骤如下…