Let’s start with how a mutation looks like in GraphQL, A simple “createEmployer” and response looks below.

To work with Mutation , we need a GraphQL variables, Mutation request. You can also choose to pass the variables(data) along with the mutation request.

But is always better to keep them seperate for simplicity.Let’s start with creating a folder structure.

Now create a file called createEmployerQuery.graphql and add the below code snippet in the file

mutation($employer:EmployerParam ) {
  createmployer(employer: $employer) {

Once you have the Query variable in place , we will add another file called createEmployerVariables.graphql which will contain all the variables we need.

  "employer": {
    "companyName": "foo",
    "Region": "sdf",
    "Email": "somefmao.com",
    "Phone": "1987683433"

We will now create a feature fill that will combine these two files and run them as once.

Feature: Create Employer 
  * url 'AuthURL' 
  * path 'token' 
  * form field grant_type = 'password' 
  * form field username = username 
  * form field password = password 
  * form field client_id = appId 
  * form field client_secret = appSecret 
  * form field scope = 'yourScopeURL' 
  * method post 
  * status 200 
  * print response

Scenario: Create all employer details     
Given def query = read('createEmployerQuery.graphql')     Given def variables = read('createEmployerVariable.graphql') #And def variables = { name: 'Charmander' }     
And request { query: '#(query)', variables: '#(variables)' } #And request { query: '#(query)' }      
When method post     
* print response     
Then status 200     

To run this we need a runner class.

package employer;
import org.junit.runner.RunWith;
import com.intuit.karate.junit4.Karate;
import com.intuit.karate.KarateOptions;
@KarateOptions(features = "classpath:employer/createEmployer.feature")
public class EmployerRunner {