Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Passing the Graphql schema as JSON request body in REST

Bimal
Tera Contributor

Hi ,

I want to pass the Graphql schema as the JSON request body in REST Message.

This is my Grapql Query 

query listComponents($inputListComponentsInput) {
  serviceslistComponents(input$input) {
    pageInfo {
      totalCount
      pageSize
      totalPages
      currentPage
      previousPage
      nextPage
    }
    items {
      service_long_idcomponentId
      service_namecomponentName
      service_idcomponentCode
      service_descdescription
      division
    }
  }
}
Variables :
{
    "input": {
        "filter": {
            "componentIds": {
                "in": []
            },
            "active": {
                "eq": true
            },
            "lifeCycleStatus": {
                "ne": "Retired"
            },
            "componentName": {
                "contains": ""
            }
        },
        "pagination": {
            "size": 3000,
            "page": 1
        }
    }
}
2 REPLIES 2

MartinM03821709
Tera Contributor

You just need to wrap it:

like this:

{ "query": `{ places (orderBy: title_ASC,first: 100){ id title perex images { height src width } } }`, }

 

There a single property "query" that will contain your graphql query. You can do it as multiline string or I found this nice service: https://datafetcher.com/graphql-json-body-converter

 

{
"query": "query listComponents($input: ListComponentsInput) { services: listComponents(input: $input) { pageInfo { totalCount pageSize totalPages currentPage previousPage nextPage } items { service_long_id: componentId service_name: componentName service_id: componentCode service_desc: description division } }}Variables :{ \"input\": { \"filter\": { \"componentIds\": { \"in\": [] }, \"active\": { \"eq\": true }, \"lifeCycleStatus\": { \"ne\": \"Retired\" }, \"componentName\": { \"contains\": \"\" } }, \"pagination\": { \"size\": 3000, \"page\": 1 } }}"
}

stuart012br
Kilo Contributor

Hello,

You want to send your GraphQL query and variables via a REST message as a JSON payload. In REST, GraphQL requests are usually sent as POST requests with a JSON body that contains both the query and the variables.