66
77module . exports = {
88 Query : {
9+ // query to look up data on an individual warehouse
910 warehouse : ( parent , args , context ) => {
1011 const query = 'SELECT * FROM warehouses WHERE "warehouseId" = $1 LIMIT 1' ;
1112 const values = [ args . warehouseId ] ;
1213 return context . psqlPool . query ( query , values )
1314 . then ( ( data ) => data . rows [ 0 ] )
1415 . catch ( ( err ) => console . log ( 'ERROR LOOKING UP WAREHOUSE' , err ) ) ;
1516 } ,
17+ // query to return data on all warehouses
1618 warehouses : ( parent , args , context ) => {
1719 const query = 'SELECT * FROM warehouses' ;
1820 return context . psqlPool . query ( query )
@@ -21,6 +23,7 @@ module.exports = {
2123 } ,
2224 } ,
2325 Mutation : {
26+ // mutation to add a warehouse to the database
2427 addWarehouse : ( parent , args , context ) => {
2528 const query = 'INSERT INTO warehouses (name, "addressId") VALUES ($1, $2) RETURNING *' ;
2629 const values = [ args . name , args . addressId ] ;
@@ -34,6 +37,7 @@ module.exports = {
3437 . catch ( ( err ) => console . log ( 'ERROR INSERTING WAREHOUSE' , err ) ) )
3538 . catch ( ( err ) => console . log ( 'ERROR CONNECTING WHILE ADDING WAREHOUSE' , err ) ) ;
3639 } ,
40+ // mutation to update details of a warehouse
3741 updateWarehouse : ( parent , args , context ) => {
3842 let query = 'UPDATE warehouses SET ' ;
3943 const values = [ args . warehouseId ] ;
@@ -59,6 +63,7 @@ module.exports = {
5963 . catch ( ( err ) => console . log ( 'ERROR UPDATING WAREHOUSE' , err ) ) )
6064 . catch ( ( err ) => console . log ( 'ERROR CONNECTING WHILE UPDATING WAREHOUSE' , err ) ) ;
6165 } ,
66+ // mutation to delete a warehouse from the database
6267 deleteWarehouse : ( parent , args , context ) => {
6368 const query = 'DELETE FROM warehouses WHERE "warehouseId"=$1 RETURNING *' ;
6469 const values = [ args . warehouseId ] ;
@@ -73,6 +78,8 @@ module.exports = {
7378 . catch ( ( err ) => console . log ( 'ERROR CONNECTING WHILE DELETING WAREHOUSE' , err ) ) ;
7479 } ,
7580 } ,
81+
82+ // type resolver for nested type: Address
7683 Warehouse : {
7784 address : ( parent , args , context ) => {
7885 const query = 'SELECT * FROM addresses WHERE id=$1 LIMIT 1' ;
0 commit comments