0

I am using CommerceTools GraphQL custom fields, which need to be escaped strings, the graphql tooling I am using is gql and URQL's Mutation component the following query works in CT's playground.

mutation AddCustomerName {
  updateCustomer(
    version: 75, 
    id: "customer id", 
    actions: [
      {
        # The action to change the first name.
        setFirstName: { firstName: "John" }
      }
     {setCustomField:{name:"customer_CF_Gender",value:"\"Female\""}}
    ]
  ) {
    id
    version
    email
    firstName
    lastName
    custom {
      customFieldsRaw(includeNames: ["customer_CF_Gender"]) {
        name
        value
      }
    }
  }
}

but if I do the following

export function exampleMutation() { 
    return `mutation AddCustomerName {
        updateCustomer(
          version: 75, 
          id: "customer id goes here", 
          actions: [
            {
              # The action to change the first name.
              setFirstName: { firstName: "John" }
            }
           {setCustomField:{name:"customer_CF_Gender",value: "\"Female\"" }}
          ]
        ) {
          id
          version
          email
          firstName
          lastName
          custom {
            customFieldsRaw(includeNames: ["customer_CF_Gender"]) {
              name
              value
            }
          }
        }
      }`

}

The gql returns a syntax error at the returned string

GraphQLError: Syntax Error: Expected ":", found String "".

This is also the case if I use gql to prep it.

which that error seems reasonable, but I'm not finding any way to add in an escaped string which is what I need to do.

I don't mind if the solution is to do it as variables, but I'm not finding any way that the variables work either, so if you think it needs to be done with variables please show me how

ON EDIT: I think, by checking the network requests etc. and trying various variations that there is a step somewhere in URQL where the escaped string gets unescaped again, that is to say where "/"Female/"" turns into "Female" but // doesn't get past this either. Although I am also considering it can be somewhere in our whole transpilation / compilation process that it happens, which essentially makes it difficult for me to come up with a small enough to reproduce problem example.

user254694
  • 1,461
  • 2
  • 23
  • 46

0 Answers0