Search code examples
angulargraphqlapollo

GraphQL gql Syntax Error: Expected Name, found $


I'm trying to update some data in GraphQL (Angular Apollo) but when I run my code it shows GraphQLError: Syntax Error: Expected Name, found "$"

I'm doing this:

const CONFIRM_CITA = gql`
  {
    mutation changeConfirmationStatus ($centroConfirmacion: String!, $estadoConfirmacion: String!, $id: String!) {
      changeConfirmationStatus(centroConfirmacion: $centroConfirmacion, estadoConfirmacion: $estadoConfirmacion, id: $id) {
        id,
        estadoConfirmacion
      }
    }
  }
`
...
export class CitasComponent implements OnInit {
...

update(idCita: string){
  this.apollo.mutate({
          mutation: CONFIRM_CITA,
          variables: {
            centroConfirmacion: "",
            estadoConfirmacion: "Confirmado",
            id: IdCita,
          }
        })
}

Why is it failing? thanks


Solution

  • You shouldn't have curly brackets after gql, see below:

    const CONFIRM_CITA = gql`
        mutation changeConfirmationStatus ($centroConfirmacion: String!, $estadoConfirmacion: String!, $id: String!) {
          changeConfirmationStatus(centroConfirmacion: $centroConfirmacion, estadoConfirmacion: $estadoConfirmacion, id: $id) {
            id,
            estadoConfirmacion
          }
        }
    `