How to make a request("query") to an API in graphql using Typescript in NodeJS

Viewed 24

I need some guidance on how to make a request or query using graphql. I have done similar tasks using JSON, but in this case I am inexperienced using Graphql. I have the body code of the API query that I show below, with the 4 fields that I must pass as dynamic variables in each request. Do you know of any way to do it or some site that you can consult that clearly shows the procedure. Thanks in advance. There are different parameters that can be set up in the request:

 `checkIn: "2022-09-28",
 checkOut: "2022-09-29",
 occupancies: [{ paxes: [{age: 30}, {age: 30}] }],
 hotels: ["1"],` 

These are the interfaces I defined:

`
export interface SearchRQ{   
checkIn:string;
checkOut:string;
occupancies: Occupancy[];
hotels: string[];
nationality: string

} export interface Occupancy { paxes: Pax[]; } export interface Pax { age: number; }`

   *And this is a part of the body of the query:*

         
    ```
    query {
    hotelX {
    search(
    criteria: { 
    checkIn: "2022-12-28",
    checkOut: "2022-12-29",
    occupancies: [{ paxes: [{age: 30}, {age: 30}] }],
    hotels: ["1","2"],
    currency: "EUR",
    market: "ES",
    language: "es",
    nationality: "ES"
   },
   settings: {
    client: "client_demo",
    context: "HOTELTEST",
    auditTransactions: false,
    testMode: true,
    timeout: 25000
   },
   filter: {
    access: {
      includes: ["0"]
    }
   }) {
       context
   errors{
    code
    type
    description
   }
   warnings{
    code
    type
    description
   }
   options {
    id
    accessCode
    supplierCode
    hotelCode
    hotelName
    boardCode
    paymentType
    status
    occupancies {
      id
      paxes {
        age
      }
    }
    rooms {
      occupancyRefId
      code
      description
      refundable
      roomPrice {
        price {
          currency
          binding
          net
          gross
             exchange {
            currency
             rate
           }
         }

         ```
0 Answers
Related