Escape backslash in Angular for the http post call on GraphQL
I am trying to save some data using GraphQL which contains backslash in its input in my Angular 5 app.
For example, while creating a table I want to keep table name as IndianCars
Below is the body of HTTP post call:
{"query":"mutation { createTable(input:[{name:"IndianCars"}]) { id } }"}
Note: name is a string that's the reason I have added "" to escape.
But GraphQL is throwing an error:
'SyntaxError: Unexpected token ' in JSON
I have tried with replacing it. The table name can be anything, an input from UI.So according to that, I am building the HTTP Post call body dynamically as below.
createGraphQLBodyObjectForPostCall(tableName) {
const newTableName = tableName.replace(/\/g, '\\');
const bodyObject = {"query":"mutation { createTable(input:[{name:\"' + newTableName + '\"}]) { id } }"};
return bodyObject;
}
but I want to create the table with the exact same name as IndianCars
I just want to escape it from the HTTP post-call, but in DB it must save the exact input that we are sending.
javascript angular typescript graphql
add a comment |
I am trying to save some data using GraphQL which contains backslash in its input in my Angular 5 app.
For example, while creating a table I want to keep table name as IndianCars
Below is the body of HTTP post call:
{"query":"mutation { createTable(input:[{name:"IndianCars"}]) { id } }"}
Note: name is a string that's the reason I have added "" to escape.
But GraphQL is throwing an error:
'SyntaxError: Unexpected token ' in JSON
I have tried with replacing it. The table name can be anything, an input from UI.So according to that, I am building the HTTP Post call body dynamically as below.
createGraphQLBodyObjectForPostCall(tableName) {
const newTableName = tableName.replace(/\/g, '\\');
const bodyObject = {"query":"mutation { createTable(input:[{name:\"' + newTableName + '\"}]) { id } }"};
return bodyObject;
}
but I want to create the table with the exact same name as IndianCars
I just want to escape it from the HTTP post-call, but in DB it must save the exact input that we are sending.
javascript angular typescript graphql
Did you try:{"query":"mutation { createTable(input:[{name:"Indian\Cars"}]) { id } }"}
– AkshayM
Nov 13 '18 at 6:51
You can also try {"query":"mutation{createTable(input:[{name:'Indian\Cars'}]){id}}"}. Check the link: unserialize.com/s/2415ff6d-890e-a829-1397-000027c4f16e
– Prasad Wargad
Nov 13 '18 at 6:53
@AkshayM I need to construct the post-call body dynamically, in the service, before I do an API call. Yes, If I add Indian\Cars will work, but how to achieve it from the service as I mentioned.
– Vishal Biradar
Nov 14 '18 at 4:53
add a comment |
I am trying to save some data using GraphQL which contains backslash in its input in my Angular 5 app.
For example, while creating a table I want to keep table name as IndianCars
Below is the body of HTTP post call:
{"query":"mutation { createTable(input:[{name:"IndianCars"}]) { id } }"}
Note: name is a string that's the reason I have added "" to escape.
But GraphQL is throwing an error:
'SyntaxError: Unexpected token ' in JSON
I have tried with replacing it. The table name can be anything, an input from UI.So according to that, I am building the HTTP Post call body dynamically as below.
createGraphQLBodyObjectForPostCall(tableName) {
const newTableName = tableName.replace(/\/g, '\\');
const bodyObject = {"query":"mutation { createTable(input:[{name:\"' + newTableName + '\"}]) { id } }"};
return bodyObject;
}
but I want to create the table with the exact same name as IndianCars
I just want to escape it from the HTTP post-call, but in DB it must save the exact input that we are sending.
javascript angular typescript graphql
I am trying to save some data using GraphQL which contains backslash in its input in my Angular 5 app.
For example, while creating a table I want to keep table name as IndianCars
Below is the body of HTTP post call:
{"query":"mutation { createTable(input:[{name:"IndianCars"}]) { id } }"}
Note: name is a string that's the reason I have added "" to escape.
But GraphQL is throwing an error:
'SyntaxError: Unexpected token ' in JSON
I have tried with replacing it. The table name can be anything, an input from UI.So according to that, I am building the HTTP Post call body dynamically as below.
createGraphQLBodyObjectForPostCall(tableName) {
const newTableName = tableName.replace(/\/g, '\\');
const bodyObject = {"query":"mutation { createTable(input:[{name:\"' + newTableName + '\"}]) { id } }"};
return bodyObject;
}
but I want to create the table with the exact same name as IndianCars
I just want to escape it from the HTTP post-call, but in DB it must save the exact input that we are sending.
javascript angular typescript graphql
javascript angular typescript graphql
edited Nov 13 '18 at 7:41
Vishal Biradar
asked Nov 13 '18 at 6:49
Vishal BiradarVishal Biradar
641616
641616
Did you try:{"query":"mutation { createTable(input:[{name:"Indian\Cars"}]) { id } }"}
– AkshayM
Nov 13 '18 at 6:51
You can also try {"query":"mutation{createTable(input:[{name:'Indian\Cars'}]){id}}"}. Check the link: unserialize.com/s/2415ff6d-890e-a829-1397-000027c4f16e
– Prasad Wargad
Nov 13 '18 at 6:53
@AkshayM I need to construct the post-call body dynamically, in the service, before I do an API call. Yes, If I add Indian\Cars will work, but how to achieve it from the service as I mentioned.
– Vishal Biradar
Nov 14 '18 at 4:53
add a comment |
Did you try:{"query":"mutation { createTable(input:[{name:"Indian\Cars"}]) { id } }"}
– AkshayM
Nov 13 '18 at 6:51
You can also try {"query":"mutation{createTable(input:[{name:'Indian\Cars'}]){id}}"}. Check the link: unserialize.com/s/2415ff6d-890e-a829-1397-000027c4f16e
– Prasad Wargad
Nov 13 '18 at 6:53
@AkshayM I need to construct the post-call body dynamically, in the service, before I do an API call. Yes, If I add Indian\Cars will work, but how to achieve it from the service as I mentioned.
– Vishal Biradar
Nov 14 '18 at 4:53
Did you try:
{"query":"mutation { createTable(input:[{name:"Indian\Cars"}]) { id } }"}
– AkshayM
Nov 13 '18 at 6:51
Did you try:
{"query":"mutation { createTable(input:[{name:"Indian\Cars"}]) { id } }"}
– AkshayM
Nov 13 '18 at 6:51
You can also try {"query":"mutation{createTable(input:[{name:'Indian\Cars'}]){id}}"}. Check the link: unserialize.com/s/2415ff6d-890e-a829-1397-000027c4f16e
– Prasad Wargad
Nov 13 '18 at 6:53
You can also try {"query":"mutation{createTable(input:[{name:'Indian\Cars'}]){id}}"}. Check the link: unserialize.com/s/2415ff6d-890e-a829-1397-000027c4f16e
– Prasad Wargad
Nov 13 '18 at 6:53
@AkshayM I need to construct the post-call body dynamically, in the service, before I do an API call. Yes, If I add Indian\Cars will work, but how to achieve it from the service as I mentioned.
– Vishal Biradar
Nov 14 '18 at 4:53
@AkshayM I need to construct the post-call body dynamically, in the service, before I do an API call. Yes, If I add Indian\Cars will work, but how to achieve it from the service as I mentioned.
– Vishal Biradar
Nov 14 '18 at 4:53
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275319%2fescape-backslash-in-angular-for-the-http-post-call-on-graphql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275319%2fescape-backslash-in-angular-for-the-http-post-call-on-graphql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you try:
{"query":"mutation { createTable(input:[{name:"Indian\Cars"}]) { id } }"}
– AkshayM
Nov 13 '18 at 6:51
You can also try {"query":"mutation{createTable(input:[{name:'Indian\Cars'}]){id}}"}. Check the link: unserialize.com/s/2415ff6d-890e-a829-1397-000027c4f16e
– Prasad Wargad
Nov 13 '18 at 6:53
@AkshayM I need to construct the post-call body dynamically, in the service, before I do an API call. Yes, If I add Indian\Cars will work, but how to achieve it from the service as I mentioned.
– Vishal Biradar
Nov 14 '18 at 4:53