Karate replace in graphql

Viewed 270

I am not sure why replace is not working. I have a graphql query:

mutation updateLocation{
  updateLocation(input: {
      address:"<address>",
      id:"<storeID>",
      name:"<name>",
      workingHours: [
                {
                closingTime:"<closingTime>",
                isClosed:false,
                openingTime:"<openingTime>"
                }
      .......

And in feature file I have this:

 Given def query = read ('classpath:graphQL/updateStore.graphql')
    * replace query.address = "<address>"
    * replace query.regionId = "<regionId>"
    * replace query.name = "<name>"
    * replace query.closingTime = "<closingTime>"
    * replace query.openingTime = "<openingTime>"
    * replace query.storeID = storeId
    And request { query : '#(query)'}
    When method post
    Then status 200



    Examples:
    |address            |regionId       |name        |closingTime   |openingTime    |
    |Adrs1              |286            |st1         |20:00         |10:00          |               

The replace works for address, regionid, and name but it does not work for closing time or opening time, these two values stay empty.

Also if I define header in background like this:

Given header Authorization = 'Bearer ' + token

I still have to add this line for each request in the same scenario, or I have been missing something?

1 Answers

Works for me:

* def query = 'closingTime:"<closingTime>"'
* replace query.closingTime = '20:00'
* match query == 'closingTime:"20:00"'

So please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Note that * replace query.closingTime = closingTime should work. I recommend avoiding confusion by using different names for the Examples columns.

Related