From be213f427e09fa9339d4542659e28688bd228a85 Mon Sep 17 00:00:00 2001 From: graphan Date: Wed, 19 Oct 2016 20:06:10 +0200 Subject: [PATCH] connecting with GraphQL API: https://github.com/apollostack/frontpage-server --- README.md | 16 ++++++++++++++++ app/client.js | 2 +- app/components/Lang/Lang.js | 12 ++++-------- app/components/Menu/Menu.js | 12 ++++-------- app/components/Page/Page.js | 15 ++++----------- app/server.js | 2 +- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index a2d548f..ef7ab18 100644 --- a/README.md +++ b/README.md @@ -61,3 +61,19 @@ Best way to keep up to date is check the [issues](https://github.com/WeLikeGraph 1. Any suggestions/improvements/bugs can be in the form of Pull Requests, or creating an issue. 2. Coding guidelines: [Airbnb's Style Guide](https://github.com/airbnb/javascript) + +I have already applied your hints. I just forked `react-apollo-example` and pushed [this commit](https://github.com/graphan/react-apollo-example/commit/4b0b8394d6eea335119d6d61af4e84295e660cdd). You can see that I use: http://graphql-swapi.parseapp.com. There are no any difference in the project despite the above commit. + +When I run: `npm run build` and `npm run start`, then no errors. +However, when I reach `localhost:3000`, then I have the following error in the console: +```console +RENDERING ERROR: { [Error: Network error: Unexpected token <] + graphQLErrors: null, + networkError: [SyntaxError: Unexpected token <], + stack: 'Error\n at new t (/home/tommyjs/Desktop/WLGQL/copy/react-apollo-example/dist/server.js:7:13556)\n at /home/tommyjs/Desktop/WLGQL/copy/react-apollo-example/dist/server.js:31:28905\n at /home/tommyjs/Desktop/WLGQL/copy/react-apollo-example/dist/server.js:32:6321\n at Array.forEach (native)\n at /home/tommyjs/Desktop/WLGQL/copy/react-apollo-example/dist/server.js:32:6284\n at /home/tommyjs/Desktop/WLGQL/copy/react-apollo-example/dist/server.js:38:7557\n at i (/home/tommyjs/Desktop/WLGQL/copy/react-apollo-example/dist/server.js:38:7325)\n at m (/home/tommyjs/Desktop/WLGQL/copy/react-apollo-example/dist/server.js:38:8190)\n at e.broadcastQueries (/home/tommyjs/Desktop/WLGQL/copy/react-apollo-example/dist/server.js:32:6246)\n at e.broadcastNewStore (/home/tommyjs/Desktop/WLGQL/copy/react-apollo-example/dist/server.js:31:27393)', + message: 'Network error: Unexpected token <', + extraInfo: undefined } +``` + +What might be the root cause? +I use `graphql@0.4.14`. I installed also `graphql@0.7.2`, but the same error. \ No newline at end of file diff --git a/app/client.js b/app/client.js index dee39a1..0de6244 100644 --- a/app/client.js +++ b/app/client.js @@ -11,7 +11,7 @@ import App from 'App'; // rembmer to change this endpoint accordingly - here is no access to .env file // ${HOST}:${GRAPHQL_PORT}/${GRAPHQL_ENDPOINT} -const networkInterface = createNetworkInterface('http://graphql-swapi.parseapp.com/'); +const networkInterface = createNetworkInterface('http://localhost:8080/graphql'); const client = new ApolloClient({ networkInterface, diff --git a/app/components/Lang/Lang.js b/app/components/Lang/Lang.js index 73f074b..52bb152 100644 --- a/app/components/Lang/Lang.js +++ b/app/components/Lang/Lang.js @@ -16,7 +16,7 @@ const Lang = ({ language, changeLang, data }) => { } return ( -
+
Lang
); }; @@ -35,13 +35,9 @@ const LangWithState = connect( )(Lang); const PageWithDataAndState = graphql(gql` - query allPlanets { - allPlanets { - edges { - node { - id - } - } + query allPosts { + posts { + id } } `)(LangWithState); diff --git a/app/components/Menu/Menu.js b/app/components/Menu/Menu.js index 5492829..69aee8e 100644 --- a/app/components/Menu/Menu.js +++ b/app/components/Menu/Menu.js @@ -17,18 +17,14 @@ const Menu = ({ data }) => { } return ( -
+
Menu
); }; const MenuWithData = graphql(gql` - query allPeople { - allPeople { - edges { - node { - id - } - } + query allPosts { + posts { + title } } `, { diff --git a/app/components/Page/Page.js b/app/components/Page/Page.js index 3dda55e..16f2956 100644 --- a/app/components/Page/Page.js +++ b/app/components/Page/Page.js @@ -19,22 +19,15 @@ const Page = ({ data }) => { return (null); } - const { posts } = data.wp_query; - return ( -
-
+
Page
); }; const PageWithData = graphql(gql` - query allFilms { - allFilms { - edges { - node { - id - } - } + query allPosts { + posts { + votes } } `, { diff --git a/app/server.js b/app/server.js index 28d66e0..6f736d9 100644 --- a/app/server.js +++ b/app/server.js @@ -16,7 +16,7 @@ dotenv.config(); const GRAPHQL_ENDPOINT = process.env.GRAPHQL_ENDPOINT || 'graphql'; const GRAPHQL_PORT = process.env.GRAPHQL_PORT || 8000; const HOST = process.env.HOST || 'http://localhost'; -const apiUrl = 'http://graphql-swapi.parseapp.com/'; +const apiUrl = 'http://localhost:8080/graphql'; export default function render(req, res) { const client = new ApolloClient({