Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
GraphQL print function doesn't escape string correctly

I am using the following code:

const GQL_ADD_JOB = gql`
    mutation AddJob {
        addJob(title: $title, company: $company, description: $description) {
            title
            company
            description
        }
    }
    `;

And then using axios, I attempt to POST using GraphQL's print function:

request.post(
  GQL_ENDPOINT,
  {
    query: print(GQL_ADD_JOB),
    variables: {
      title: job.title,
      company: job.company,
      description: job.description,
    },
  }
)

Where job.title, job.company, and job.description can all be strings containing any character, including newlines, quotes, etc. However, calling this results in a JSON parse error. The error shows that the request sent the following data:

'{"query":"mutation AddJob {\n addJob(title: $title, company: $company, description: $description) {\n title\n company\n description\n }\n}","variables":{"title":"Route Service Sales Representative - 3rd Shift","company":"Cintas","description":"test desc"}}'

When I use this data and manually perform a POST via curl, I get the following error:

{"message":"Syntax Error: Cannot parse the unexpected character "\\".","extensions":{"code":"GRAPHQL_PARSE_FAILED","exception":{"stacktrace":["GraphQLError: Syntax Error: Cannot parse the unexpected character "\\"."," at syntaxError (/home/user/repos/comp/node_modules/graphql/error/syntaxError.js:15:10)"," at readToken (/home/user/repos/comp/node_modules/graphql/language/lexer.js:360:40)"," at Lexer.lookahead (/home/user/repos/comp/node_modules/graphql/language/lexer.js:75:108)"," at Lexer.advance (/home/user/repos/comp/node_modules/graphql/language/lexer.js:58:35)"," at Parser.expectToken (/home/user/repos/comp/node_modules/graphql/language/parser.js:1408:19)"," at Parser.many (/home/user/repos/comp/node_modules/graphql/language/parser.js:1519:10)"," at Parser.parseSelectionSet (/home/user/repos/comp/node_modules/graphql/language/parser.js:271:24)"," at Parser.parseOperationDefinition (/home/user/repos/comp/node_modules/graphql/language/parser.js:199:26)"," at Parser.parseDefinition (/home/user/repos/comp/node_modules/graphql/language/parser.js:137:23)"," at Parser.many (/home/user/repos/comp/node_modules/graphql/language/parser.js:1523:26)"]}}}

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I changed my mutation to this and now it works. I still don't fully understand why the other format didn't work.

mutation AddJob($title: String!, $company: String!, $description: String!) 
{
    addJob(title: $title, company: $company, description: $description)
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda