<?php/** * Created by PhpStorm. * User: Zero * Time: 2021/1/11 10:10 */namespaceMeibuyu\Micro\Shopify\tools;useMeibuyu\Micro\Tools\CurlRequest;useMeibuyu\Micro\Tools\HttpRequestJson;classHttpRequestGraphQLextendsHttpRequestJson{protectedstaticfunctionprepareRequest($headers=[],$data=[],$variables=null){if(is_string($data)){$postDataGraphQL=$data;}else{thrownew\Exception("Only GraphQL string is allowed!");}if(is_array($variables)){$postDataGraphQL=json_encode(['query'=>$data,'variables'=>$variables]);$headers['Content-type']='application/json';}else{$headers['Content-type']='application/graphql';}return[$headers,$postDataGraphQL];}publicstaticfunctionpost($url,$data,$headers=[],$variables=null){[$headers,$postDataGraphQL]=self::prepareRequest($headers,$data,$variables);returnCurlRequest::post($url,$postDataGraphQL,$headers);}}