type Book @model(subscriptions: null) @auth( rules: [ # allow admins to create, update and delete books { allow: groups, groups: ["Admin"] } # allow all authenticated users to view books { allow: private, operations: [read] } # allow all guest users (not authenticated) to view books { allow: public, operations: [read] } ] ) { id: ID! title: String! description: String image: String author: String featured: Boolean price: Float orders: [BookOrder] @connection(keyName: "byBook", fields: ["id"]) } type BookOrder @model(queries: null, subscriptions: null) @key(name: "byBook", fields: ["book_id", "order_id"]) @key(name: "byOrder", fields: ["order_id", "book_id"]) @auth( rules: [ # allow admins to create bookorders for customers by using customer email in lambda { allow: owner, identityClaim: "email", ownerField: "customer" } { allow: groups, groups: ["Admin"] } ] ) { id: ID! book_id: ID! order_id: ID! book: Book @connection(fields: ["book_id"]) order: Order @connection(fields: ["order_id"]) } type Order @model(subscriptions: null) @auth( rules: [ # only owner can see his orders { allow: owner, identityClaim: "email", ownerField: "customer" } # allow admins to view orders { allow: groups, groups: ["Admin"] } ] ) @key(name: "byUser", fields: ["user"]) { id: ID! user: String! date: String total: Float books: [BookOrder] @connection(keyName: "byOrder", fields: ["id"]) } enum OrderStatus { SUCCESS FAILED } input CartItem { id: ID! title: String image: String price: Float amount: Int } input ProcessOrderInput { id: ID! cart: [CartItem] total: Float! token: String! address: String } type Mutation { processOrder(input: ProcessOrderInput!): OrderStatus @function(name: "processPayment-${env}") @function(name: "createOrder-${env}") }