Network error: Unexpected token < in JSON at position 0 at new ApolloError
up vote
0
down vote
favorite

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
add a comment |
up vote
0
down vote
favorite

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
Open network tab in developers console and tell us whatApolloErroris.
– kiarashws
Nov 8 at 14:20
@kiarashws added a screenshot for the request
– Mukesh Kumar
Nov 8 at 14:26
as you can seeStatus Codeis 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
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite

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

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
javascript reactjs express graphql apollo
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 whatApolloErroris.
– kiarashws
Nov 8 at 14:20
@kiarashws added a screenshot for the request
– Mukesh Kumar
Nov 8 at 14:26
as you can seeStatus Codeis 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
add a comment |
Open network tab in developers console and tell us whatApolloErroris.
– kiarashws
Nov 8 at 14:20
@kiarashws added a screenshot for the request
– Mukesh Kumar
Nov 8 at 14:26
as you can seeStatus Codeis 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
add a comment |
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
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
|
show 3 more comments
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
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
|
show 3 more comments
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
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
|
show 3 more comments
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
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
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
|
show 3 more comments
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
|
show 3 more comments
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
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
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
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
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
Open network tab in developers console and tell us what
ApolloErroris.– 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 Codeis 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