Network error: Unexpected token < in JSON at position 0 at new ApolloError









up vote
0
down vote

favorite












enter image description here



const httpLink = createHttpLink(
uri: 'http://localhost:3090/'
)

const client = new ApolloClient(
link: httpLink,
cache: new InMemoryCache()
)

client.query(
query: gql`
query users
email

`,
)
.then(data => console.log(data))
.catch(error => console.error(error));


This query gives an error when fetching from client-side code but when i execute this query in browser on http://localhost:3090/graphql it fetches data correctly










share|improve this question























  • Open network tab in developers console and tell us what ApolloError is.
    – kiarashws
    Nov 8 at 14:20










  • @kiarashws added a screenshot for the request
    – Mukesh Kumar
    Nov 8 at 14:26










  • as you can see Status Code is 404(not found), which means given url is incorrect.
    – kiarashws
    Nov 8 at 14:35










  • Looks like your request is not answered with a JSON object but an HTML page <HTML>.... Typically the case for unhandled errors, where you are served a default error page. Because you're connecting to the root URL, my guess is a 404?
    – Freek Wiekmeijer
    Nov 8 at 14:54















up vote
0
down vote

favorite












enter image description here



const httpLink = createHttpLink(
uri: 'http://localhost:3090/'
)

const client = new ApolloClient(
link: httpLink,
cache: new InMemoryCache()
)

client.query(
query: gql`
query users
email

`,
)
.then(data => console.log(data))
.catch(error => console.error(error));


This query gives an error when fetching from client-side code but when i execute this query in browser on http://localhost:3090/graphql it fetches data correctly










share|improve this question























  • Open network tab in developers console and tell us what ApolloError is.
    – kiarashws
    Nov 8 at 14:20










  • @kiarashws added a screenshot for the request
    – Mukesh Kumar
    Nov 8 at 14:26










  • as you can see Status Code is 404(not found), which means given url is incorrect.
    – kiarashws
    Nov 8 at 14:35










  • Looks like your request is not answered with a JSON object but an HTML page <HTML>.... Typically the case for unhandled errors, where you are served a default error page. Because you're connecting to the root URL, my guess is a 404?
    – Freek Wiekmeijer
    Nov 8 at 14:54













up vote
0
down vote

favorite









up vote
0
down vote

favorite











enter image description here



const httpLink = createHttpLink(
uri: 'http://localhost:3090/'
)

const client = new ApolloClient(
link: httpLink,
cache: new InMemoryCache()
)

client.query(
query: gql`
query users
email

`,
)
.then(data => console.log(data))
.catch(error => console.error(error));


This query gives an error when fetching from client-side code but when i execute this query in browser on http://localhost:3090/graphql it fetches data correctly










share|improve this question















enter image description here



const httpLink = createHttpLink(
uri: 'http://localhost:3090/'
)

const client = new ApolloClient(
link: httpLink,
cache: new InMemoryCache()
)

client.query(
query: gql`
query users
email

`,
)
.then(data => console.log(data))
.catch(error => console.error(error));


This query gives an error when fetching from client-side code but when i execute this query in browser on http://localhost:3090/graphql it fetches data correctly







javascript reactjs express graphql apollo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 14:40









trixn

4,5171526




4,5171526










asked Nov 8 at 14:18









Mukesh Kumar

167112




167112











  • Open network tab in developers console and tell us what ApolloError is.
    – kiarashws
    Nov 8 at 14:20










  • @kiarashws added a screenshot for the request
    – Mukesh Kumar
    Nov 8 at 14:26










  • as you can see Status Code is 404(not found), which means given url is incorrect.
    – kiarashws
    Nov 8 at 14:35










  • Looks like your request is not answered with a JSON object but an HTML page <HTML>.... Typically the case for unhandled errors, where you are served a default error page. Because you're connecting to the root URL, my guess is a 404?
    – Freek Wiekmeijer
    Nov 8 at 14:54

















  • Open network tab in developers console and tell us what ApolloError is.
    – kiarashws
    Nov 8 at 14:20










  • @kiarashws added a screenshot for the request
    – Mukesh Kumar
    Nov 8 at 14:26










  • as you can see Status Code is 404(not found), which means given url is incorrect.
    – kiarashws
    Nov 8 at 14:35










  • Looks like your request is not answered with a JSON object but an HTML page <HTML>.... Typically the case for unhandled errors, where you are served a default error page. Because you're connecting to the root URL, my guess is a 404?
    – Freek Wiekmeijer
    Nov 8 at 14:54
















Open network tab in developers console and tell us what ApolloError is.
– kiarashws
Nov 8 at 14:20




Open network tab in developers console and tell us what ApolloError is.
– kiarashws
Nov 8 at 14:20












@kiarashws added a screenshot for the request
– Mukesh Kumar
Nov 8 at 14:26




@kiarashws added a screenshot for the request
– Mukesh Kumar
Nov 8 at 14:26












as you can see Status Code is 404(not found), which means given url is incorrect.
– kiarashws
Nov 8 at 14:35




as you can see Status Code is 404(not found), which means given url is incorrect.
– kiarashws
Nov 8 at 14:35












Looks like your request is not answered with a JSON object but an HTML page <HTML>.... Typically the case for unhandled errors, where you are served a default error page. Because you're connecting to the root URL, my guess is a 404?
– Freek Wiekmeijer
Nov 8 at 14:54





Looks like your request is not answered with a JSON object but an HTML page <HTML>.... Typically the case for unhandled errors, where you are served a default error page. Because you're connecting to the root URL, my guess is a 404?
– Freek Wiekmeijer
Nov 8 at 14:54













1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










The graphql endpoint you are posting your queries to is missing the /graphql. So your server probably returns an html document containing the 404 error message that starts with < from <html.... Apollo tries to parse that as the query result and fails to do so.



Check that httpLink is actually localhost:3090/graphql.



Also the syntax of a query is either:




users
email




or if you want to name the query:



query Users 
users
email







share|improve this answer






















  • adding /graphql gives an error bad request
    – Mukesh Kumar
    Nov 8 at 14:38










  • @MukeshKumar please add the full error message to your question.
    – trixn
    Nov 8 at 14:39










  • after adding /graphql ..?
    – Mukesh Kumar
    Nov 8 at 14:41










  • @MukeshKumar Yes. I can't tell you why it fails without the message.
    – trixn
    Nov 8 at 14:42










  • POST localhost:3090/graphql 400 (Bad Request) index.js:1452 Error: Network error: Response not successful: Received status code 400 at new ApolloError (ApolloError.js:58) at QueryManager.js:522 at QueryManager.js:982 at Array.forEach (<anonymous>) at QueryManager.js:981 at Map.forEach (<anonymous>) at QueryManager.broadcastQueries (QueryManager.js:977) at QueryManager.js:477
    – Mukesh Kumar
    Nov 8 at 14:42











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',
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
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53209623%2fnetwork-error-unexpected-token-in-json-at-position-0-at-new-apolloerror%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










The graphql endpoint you are posting your queries to is missing the /graphql. So your server probably returns an html document containing the 404 error message that starts with < from <html.... Apollo tries to parse that as the query result and fails to do so.



Check that httpLink is actually localhost:3090/graphql.



Also the syntax of a query is either:




users
email




or if you want to name the query:



query Users 
users
email







share|improve this answer






















  • adding /graphql gives an error bad request
    – Mukesh Kumar
    Nov 8 at 14:38










  • @MukeshKumar please add the full error message to your question.
    – trixn
    Nov 8 at 14:39










  • after adding /graphql ..?
    – Mukesh Kumar
    Nov 8 at 14:41










  • @MukeshKumar Yes. I can't tell you why it fails without the message.
    – trixn
    Nov 8 at 14:42










  • POST localhost:3090/graphql 400 (Bad Request) index.js:1452 Error: Network error: Response not successful: Received status code 400 at new ApolloError (ApolloError.js:58) at QueryManager.js:522 at QueryManager.js:982 at Array.forEach (<anonymous>) at QueryManager.js:981 at Map.forEach (<anonymous>) at QueryManager.broadcastQueries (QueryManager.js:977) at QueryManager.js:477
    – Mukesh Kumar
    Nov 8 at 14:42















up vote
0
down vote



accepted










The graphql endpoint you are posting your queries to is missing the /graphql. So your server probably returns an html document containing the 404 error message that starts with < from <html.... Apollo tries to parse that as the query result and fails to do so.



Check that httpLink is actually localhost:3090/graphql.



Also the syntax of a query is either:




users
email




or if you want to name the query:



query Users 
users
email







share|improve this answer






















  • adding /graphql gives an error bad request
    – Mukesh Kumar
    Nov 8 at 14:38










  • @MukeshKumar please add the full error message to your question.
    – trixn
    Nov 8 at 14:39










  • after adding /graphql ..?
    – Mukesh Kumar
    Nov 8 at 14:41










  • @MukeshKumar Yes. I can't tell you why it fails without the message.
    – trixn
    Nov 8 at 14:42










  • POST localhost:3090/graphql 400 (Bad Request) index.js:1452 Error: Network error: Response not successful: Received status code 400 at new ApolloError (ApolloError.js:58) at QueryManager.js:522 at QueryManager.js:982 at Array.forEach (<anonymous>) at QueryManager.js:981 at Map.forEach (<anonymous>) at QueryManager.broadcastQueries (QueryManager.js:977) at QueryManager.js:477
    – Mukesh Kumar
    Nov 8 at 14:42













up vote
0
down vote



accepted







up vote
0
down vote



accepted






The graphql endpoint you are posting your queries to is missing the /graphql. So your server probably returns an html document containing the 404 error message that starts with < from <html.... Apollo tries to parse that as the query result and fails to do so.



Check that httpLink is actually localhost:3090/graphql.



Also the syntax of a query is either:




users
email




or if you want to name the query:



query Users 
users
email







share|improve this answer














The graphql endpoint you are posting your queries to is missing the /graphql. So your server probably returns an html document containing the 404 error message that starts with < from <html.... Apollo tries to parse that as the query result and fails to do so.



Check that httpLink is actually localhost:3090/graphql.



Also the syntax of a query is either:




users
email




or if you want to name the query:



query Users 
users
email








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 8 at 14:51

























answered Nov 8 at 14:37









trixn

4,5171526




4,5171526











  • adding /graphql gives an error bad request
    – Mukesh Kumar
    Nov 8 at 14:38










  • @MukeshKumar please add the full error message to your question.
    – trixn
    Nov 8 at 14:39










  • after adding /graphql ..?
    – Mukesh Kumar
    Nov 8 at 14:41










  • @MukeshKumar Yes. I can't tell you why it fails without the message.
    – trixn
    Nov 8 at 14:42










  • POST localhost:3090/graphql 400 (Bad Request) index.js:1452 Error: Network error: Response not successful: Received status code 400 at new ApolloError (ApolloError.js:58) at QueryManager.js:522 at QueryManager.js:982 at Array.forEach (<anonymous>) at QueryManager.js:981 at Map.forEach (<anonymous>) at QueryManager.broadcastQueries (QueryManager.js:977) at QueryManager.js:477
    – Mukesh Kumar
    Nov 8 at 14:42

















  • adding /graphql gives an error bad request
    – Mukesh Kumar
    Nov 8 at 14:38










  • @MukeshKumar please add the full error message to your question.
    – trixn
    Nov 8 at 14:39










  • after adding /graphql ..?
    – Mukesh Kumar
    Nov 8 at 14:41










  • @MukeshKumar Yes. I can't tell you why it fails without the message.
    – trixn
    Nov 8 at 14:42










  • POST localhost:3090/graphql 400 (Bad Request) index.js:1452 Error: Network error: Response not successful: Received status code 400 at new ApolloError (ApolloError.js:58) at QueryManager.js:522 at QueryManager.js:982 at Array.forEach (<anonymous>) at QueryManager.js:981 at Map.forEach (<anonymous>) at QueryManager.broadcastQueries (QueryManager.js:977) at QueryManager.js:477
    – Mukesh Kumar
    Nov 8 at 14:42
















adding /graphql gives an error bad request
– Mukesh Kumar
Nov 8 at 14:38




adding /graphql gives an error bad request
– Mukesh Kumar
Nov 8 at 14:38












@MukeshKumar please add the full error message to your question.
– trixn
Nov 8 at 14:39




@MukeshKumar please add the full error message to your question.
– trixn
Nov 8 at 14:39












after adding /graphql ..?
– Mukesh Kumar
Nov 8 at 14:41




after adding /graphql ..?
– Mukesh Kumar
Nov 8 at 14:41












@MukeshKumar Yes. I can't tell you why it fails without the message.
– trixn
Nov 8 at 14:42




@MukeshKumar Yes. I can't tell you why it fails without the message.
– trixn
Nov 8 at 14:42












POST localhost:3090/graphql 400 (Bad Request) index.js:1452 Error: Network error: Response not successful: Received status code 400 at new ApolloError (ApolloError.js:58) at QueryManager.js:522 at QueryManager.js:982 at Array.forEach (<anonymous>) at QueryManager.js:981 at Map.forEach (<anonymous>) at QueryManager.broadcastQueries (QueryManager.js:977) at QueryManager.js:477
– Mukesh Kumar
Nov 8 at 14:42





POST localhost:3090/graphql 400 (Bad Request) index.js:1452 Error: Network error: Response not successful: Received status code 400 at new ApolloError (ApolloError.js:58) at QueryManager.js:522 at QueryManager.js:982 at Array.forEach (<anonymous>) at QueryManager.js:981 at Map.forEach (<anonymous>) at QueryManager.broadcastQueries (QueryManager.js:977) at QueryManager.js:477
– Mukesh Kumar
Nov 8 at 14:42


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53209623%2fnetwork-error-unexpected-token-in-json-at-position-0-at-new-apolloerror%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

PHP code is not being executed, instead code shows on the page

Malaysia to Papua New Guinea by motorcycle?