# Visualise a GraphQL response

**URL:** <https://community.postman.com/t/visualise-a-graphql-response/42070>\
**Category:** Help Hub\
**Tags:** tests, collections, visualizer\
**Created:** [December 14, 2022, 3:01pm UTC](https://community.postman.com/t/visualise-a-graphql-response/42070 "2022-12-14T15:01:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joint-operations-sp7](https://avatars.discourse-cdn.com/v4/letter/j/6bbea6/32.png) [@joint-operations-sp7](https://community.postman.com/u/joint-operations-sp7)\
**Post date:** [December 14, 2022, 3:01pm UTC](https://community.postman.com/t/visualise-a-graphql-response/42070/1 "2022-12-14T15:01:04Z")

</div>

```auto
{
    "data": {
        "predictedImages": [
            {
                "SImg": "./media/person1_bacteria_1_lgOdnLj_QqrqfBH.jpeg",
                "SetImgID": "1",
                "alldata": [
                    {
                        "SetImgID": "1",
                        "SValue1": "50.0",
                        "SClass1": "NORMAL"
                    }
                ]
            },
            {
                "SImg": "./media/person1_bacteria_1_lgOdnLj_QqrqfBH_Eoc1So1.jpeg",
                "SetImgID": "2",
                "alldata": [
                    {
                        "SetImgID": "2",
                        "SValue1": "52.0",
                        "SClass1": "PNEUMONIA"
                    }
                ]
            }
        ]
    }
}

```

This is my graphql query, and it is working.

But not visualize

```auto
var template = `
    <table bgcolor="#FFFFFF">
        <tr>
            <th>SImg</th>
            <th>SetImgID</th>
        </tr>

        {{#each response}}
            <tr>
                <td>{{data.[0].predictedImages.[0].SImg}}</td>
                <td>{{data.[0].predictedImages.[0].SetImgID}}</td>
            </tr>
        {{/each}}
    </table>
`

// Set visualizer
pm.visualizer.set(template, {
    // Pass the response body parsed as JSON as `data`
    response: pm.response.json()
});

```

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [December 15, 2022, 12:08pm UTC](https://community.postman.com/t/visualise-a-graphql-response/42070/2 "2022-12-15T12:08:33Z")

</div>

Hi @joint-operations-sp7

Is there some text missing from this example?  
Doesn’t look to have an opening

 tag.

> [@joint-operations-sp7](#):
>
> var template = `
> 
> ```auto
> {{#each response}}
> <tr>
> <td>{{data.[0].predictedImages.[0].SImg}}</td>
> <td>{{data.[0].predictedImages.[0].SetImgID}}</td>
> </tr>
> {{/each}}
> </table>
> `;
> 
> ```

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [December 15, 2022, 3:42pm UTC](https://community.postman.com/t/visualise-a-graphql-response/42070/3 "2022-12-15T15:42:02Z")

</div>

```auto
var template = `

    <style type="text/css">
        .tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
        .tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
        .tftable tr {background-color:#ffffff;}
        .tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
        .tftable tr:hover {background-color:#e0ffff;}
    </style>
    
    <table class="tftable" border="1">
        <tr>
            <th>SImg</th>
            <th>SetImgID</th>
        </tr>
        
        {{#each response.data.predictedImages}}
            <tr id=row_{{@key}} onClick="handleClick(this.id)">
                <td id=SImg_{{@key}}>{{SImg}}</td>
                <td id=SetImgID_{{@key}}>{{SetImgID}}</td>
            </tr>
        {{/each}}
    </table>

`;

pm.visualizer.set(template, {
    response: pm.response.json()
});

```

![image](https://us1.discourse-cdn.com/getpostman/original/3X/c/5/c5e92f1b9a99d346e267cbc72e960a659fe7f6e4.png)

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [December 15, 2022, 3:53pm UTC](https://community.postman.com/t/visualise-a-graphql-response/42070/4 "2022-12-15T15:53:31Z")

</div>

I like creating ID’s for the table elements as it lets you target elements in the table.

The following example changes the SImg element to uppercase.

It’s useful if you want to format dates, etc.

```auto
var template = `

    <style type="text/css">
        .tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
        .tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
        .tftable tr {background-color:#ffffff;}
        .tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
        .tftable tr:hover {background-color:#e0ffff;}
    </style>
    
    <table class="tftable" border="1">
        <tr>
            <th>SImg</th>
            <th>SetImgID</th>
        </tr>
        
        {{#each response.data.predictedImages}}
            <tr id=row_{{@key}} onClick="handleClick(this.id)">
                <td id=SImg_{{@key}}>{{SImg}}</td>
                <td id=SetImgID_{{@key}}>{{SetImgID}}</td>
                <script type = "text/JavaScript">
                    var u = ("{{SImg}}").toUpperCase();
                    document.getElementById("SImg_{{@key}}").innerHTML = u;
                </script>
            </tr>
        {{/each}}
    </table>

`;

pm.visualizer.set(template, {
    response: pm.response.json()
});

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [September 4, 2023, 4:00pm UTC](https://community.postman.com/t/visualise-a-graphql-response/42070/5 "2023-09-04T16:00:52Z")

</div>

Closed on September 4, 2023, 4:00pm UTC

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.
