標籤:order tab create 自動產生 inf nal 查詢 custom guests
一張參考圖
說明
從我們可以方便的看出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
vulcanjs schemas&& collections