@@ -917,6 +917,81 @@ describe('Shopify', () => {
917917 ) ;
918918 } ) ;
919919
920+ it ( 'can add a hook to not throw an error when the response has errors' , ( ) => {
921+ const customerDataErrors = [
922+ {
923+ message :
924+ 'This app is not approved to use the email field. See https://partners.shopify.com/1/apps/1/customer_data for more details.' ,
925+ path : [ 'customers' , 'edges' , '0' , 'node' , 'email' ] ,
926+ extensions : {
927+ code : 'ACCESS_DENIED' ,
928+ documentation :
929+ 'https://partners.shopify.com/1/apps/1/customer_data' ,
930+ requiredAccess :
931+ 'Shopify approval is required before using the email field.'
932+ }
933+ } ,
934+ {
935+ message :
936+ 'This app is not approved to use the firstName field. See https://partners.shopify.com/1/apps/1/customer_data for more details.' ,
937+ path : [ 'customers' , 'edges' , '0' , 'node' , 'firstName' ] ,
938+ extensions : {
939+ code : 'ACCESS_DENIED' ,
940+ documentation :
941+ 'https://partners.shopify.com/1/apps/1/customer_data' ,
942+ requiredAccess :
943+ 'Shopify approval is required before using the firstName field.'
944+ }
945+ }
946+ ] ;
947+
948+ let calledWithErrors = undefined ;
949+
950+ const shopify = new Shopify ( {
951+ shopName,
952+ accessToken,
953+ hooks : {
954+ afterResponse : [
955+ ( res ) => {
956+ if ( res . body && res . body . errors ) {
957+ calledWithErrors = res . body . errors ;
958+
959+ res . body . errors = undefined ;
960+ }
961+
962+ return res ;
963+ }
964+ ]
965+ }
966+ } ) ;
967+
968+ scope . post ( '/admin/api/graphql.json' ) . reply ( 200 , {
969+ data : {
970+ customers : {
971+ edges : [
972+ {
973+ node : {
974+ id : 'gid://shopify/Customer/1234567890' ,
975+ email : null ,
976+ firstName : null
977+ }
978+ }
979+ ]
980+ }
981+ } ,
982+ errors : customerDataErrors
983+ } ) ;
984+
985+ return shopify . graphql ( 'query' ) . then ( ( result ) => {
986+ expect ( calledWithErrors ) . to . deep . equal ( customerDataErrors ) ;
987+ expect ( result . customers . edges [ 0 ] . node . id ) . to . equal (
988+ 'gid://shopify/Customer/1234567890'
989+ ) ;
990+ expect ( result . customers . edges [ 0 ] . node . email ) . to . equal ( null ) ;
991+ expect ( result . customers . edges [ 0 ] . node . firstName ) . to . equal ( null ) ;
992+ } ) ;
993+ } ) ;
994+
920995 it ( 'uses basic auth as intended' , ( ) => {
921996 const shopify = new Shopify ( { shopName, apiKey, password } ) ;
922997
0 commit comments