I made the schema.grapqhs with this content:

type Query {
    quoteData (
        id: Int @doc(description: "Id of the Quote Data")
    ): QuoteData @resolver(class: "Vendor\\Module\\Model\\Resolver\\QuoteData") @doc(description: "The Quote Data Query Returns Data about a Quote Object")
type QuoteData @doc(description: "Quote information by quote id") {
    base_currency_code: String @doc(description: "Base Currency Code from Quote Object")
    grand_total: String @doc(description: "Grand Total of Specific Quote Object items")
    customer_name: String @doc(description: "Customer Name from Quote Object")

In my code, I am using curl to get the result of my query. This is the script:

        $endpoint = "http://magento.local/graphql";
        $query = '{
    quoteData(id: 1) {

        $headers = array();
        $headers[] = 'Content-Type: application/json';
        $headers[] = 'Authorization: Bearer '.$this->getBearerToken();

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $endpoint);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $result = curl_exec($ch);

        $info = curl_getinfo($ch);
        if ((int) $info['http_code'] !== 200) {
            var_dump($info['http_code']); exit();
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $body = substr($response, $header_size);
        var_dump($body); exit();

The result of my var_dump is:

{"errors":[{"debugMessage":"Unable to unserialize value. Error: Syntax error","message":"Internal server error","extensions":{"category":"internal"},"trace":[{"file":"\/vendor\/magento\/module-graph-ql\/Controller\/GraphQl.php","line":184,"call":"Magento\\Framework\\Serialize\\Serializer\\Json::unserialize('{\n    quoteData(id: 1) {\n        base_currency_code\n        customer_name\n        grand_total\n    }\n}')"},  ...... 

Any idea what am I doing wrong here ? Thank you

1 Answer 1


I missed the: \n from my $query variable, so i changed into this:

$query = '{"query":"query {\n quoteData(id: 1) {\n base_currency_code\n customer_name\n grand_total\n }\n}"}';

and it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.