@@ -12,43 +12,42 @@ type Customer {
12
12
"""
13
13
`Customer` queries a mock `Customer` object from a demo PostgreSQL database.
14
14
The data is fetched using custom SQL queries.
15
+
16
+ Table structure for 'customer':
17
+
18
+ CREATE TABLE customer (
19
+ id SERIAL PRIMARY KEY, -- Unique identifier with sequence
20
+ name CHARACTER(50) NOT NULL, -- Customer's name, max 50 characters
21
+ email CHARACTER(50) NOT NULL, -- Customer's email, max 50 characters, must be unique
22
+ CONSTRAINT customer_email_key UNIQUE (email) -- Unique constraint on email
23
+ );
24
+
25
+ Foreign key references:
26
+ - customeraddress(customerid) references customer(id)
27
+ - "order"(customerid) references customer(id)
15
28
"""
16
29
type Query {
17
- # Fetches all customers.
30
+ # Fetches all customers.
18
31
getAllCustomers : [Customer ]
19
32
@dbquery (
20
- query : " SELECT id, name, email FROM customer"
21
- type : " postgresql"
33
+ query : " SELECT id, name, email FROM customer" ,
34
+ type : " postgresql" ,
22
35
configuration : " postgresql_config"
23
36
)
37
+
24
38
# Fetches a customer by their ID.
25
- getCustomerById (id : Int ! ): Customer
39
+ getCustomerById (id : Int ! ): Customer
26
40
@dbquery (
27
- query : " SELECT id, name, email FROM customer WHERE id = $1"
28
- type : " postgresql"
41
+ query : " SELECT id, name, email FROM customer WHERE id = $1" ,
42
+ type : " postgresql" ,
29
43
configuration : " postgresql_config"
30
44
)
31
45
32
-
33
46
# Searches customers by name using a pattern match.
34
47
searchCustomersByName (name : String ! ): [Customer ]
35
48
@dbquery (
36
- query : " SELECT id, name, email FROM customer WHERE name LIKE '%' || $1 || '%'"
37
- type : " postgresql"
49
+ query : " SELECT id, name, email FROM customer WHERE name LIKE '%' || $1 || '%'" ,
50
+ type : " postgresql" ,
38
51
configuration : " postgresql_config"
39
52
)
40
53
}
41
- type Mutation {
42
- # Updates a customer's email by their ID.
43
- updateCustomerEmail (id : Int ! , newEmail : String ! ): Customer
44
- @dbquery (
45
- query : " " "
46
- UPDATE customer
47
- SET email = $2
48
- WHERE id = $1
49
- RETURNING id, name, email
50
- """
51
- type : " postgresql"
52
- configuration : " postgresql_config"
53
- )
54
- }
0 commit comments