Created
November 20, 2019 17:13
-
-
Save dabit3/e0af16db09b6e206292d1c5cfc0d0a07 to your computer and use it in GitHub Desktop.
17 Access Patterns with GraphQL and AWS Amplify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Order @model | |
@key(name: "byCustomerByStatusByDate", fields: ["customerID", "status", "date"]) | |
@key(name: "byCustomerByDate", fields: ["customerID", "date"]) | |
@key(name: "byRepresentativebyDate", fields: ["accountRepresentativeID", "date"]) | |
@key(name: "byProduct", fields: ["productID", "id"]) | |
{ | |
id: ID! | |
customerID: ID! | |
accountRepresentativeID: ID! | |
productID: ID! | |
status: String! | |
amount: Int! | |
date: String! | |
} | |
type Customer @model | |
@key(name: "byRepresentative", fields: ["accountRepresentativeID", "id"]) { | |
id: ID! | |
name: String! | |
phoneNumber: String | |
accountRepresentativeID: ID! | |
ordersByDate: [Order] @connection(keyName: "byCustomerByDate", fields: ["id"]) | |
ordersByStatusDate: [Order] @connection(keyName: "byCustomerByStatusByDate", fields: ["id"]) | |
} | |
type Employee @model | |
@key(name: "newHire", fields: ["newHire", "id"], queryField: "employeesNewHire") | |
@key(name: "newHireByStartDate", fields: ["newHire", "startDate"], queryField: "employeesNewHireByStartDate") | |
@key(name: "byName", fields: ["name", "id"], queryField: "employeeByName") | |
@key(name: "byTitle", fields: ["jobTitle", "id"], queryField: "employeesByJobTitle") | |
@key(name: "byWarehouse", fields: ["warehouseID", "id"]) { | |
id: ID! | |
name: String! | |
startDate: String! | |
phoneNumber: String! | |
warehouseID: ID! | |
jobTitle: String! | |
newHire: String! # We have to use String type, because Boolean types cannot be sort keys | |
} | |
type Warehouse @model { | |
id: ID! | |
employees: [Employee] @connection(keyName: "byWarehouse", fields: ["id"]) | |
} | |
type AccountRepresentative @model | |
@key(name: "bySalesPeriodByOrderTotal", fields: ["salesPeriod", "orderTotal"], queryField: "repsByPeriodAndTotal") { | |
id: ID! | |
customers: [Customer] @connection(keyName: "byRepresentative", fields: ["id"]) | |
orders: [Order] @connection(keyName: "byRepresentativebyDate", fields: ["id"]) | |
orderTotal: Int | |
salesPeriod: String | |
} | |
type Inventory @model | |
@key(name: "byWarehouseID", fields: ["warehouseID"], queryField: "itemsByWarehouseID") | |
@key(fields: ["productID", "warehouseID"]) { | |
productID: ID! | |
warehouseID: ID! | |
inventoryAmount: Int! | |
} | |
type Product @model { | |
id: ID! | |
name: String! | |
orders: [Order] @connection(keyName: "byProduct", fields: ["id"]) | |
inventories: [Inventory] @connection(fields: ["id"]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That´s my question too !
I also would like to understand how to "manually" use the directives, in particular @connection for a one-to-one relationship. I had already written the resolvers (VLT scripts) needed for my "single" queries but need to retrieve additional info for an certain graphql type object, from a record in the same DynamoDB table. All without using the magic "create resources" option...
How to construct the appropriate query-resolver ?
Some where along the line:
type Project @model {
id: ID!
name: String
teamID: ID!
team: Team @connection(fields: ["teamID"])
}
type Team @model {
id: ID!
name: String!
}