Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to send request through socket, instead tries to send normal POST request. #23

Closed
MartinElvar opened this issue May 18, 2018 · 1 comment

Comments

@MartinElvar
Copy link

So i've set up my react project with Apollo & React, just after the book, i've followed the examples shown in the README. But i still can't get it to function, it does seem to connect to my Phoenix socket. but when ever i fire of a query it will simply send a post request instead.

This is my deps.

  "dependencies": {
    "@absinthe/socket-apollo-link": "^0.1.11",
    "apollo-boost": "^0.1.6",
    "graphql": "^0.13.2",
    "graphql-tag": "^2.9.2",
    "history": "^4.7.2",
    "react-apollo": "^2.1.4",
    "react-redux": "^5.0.7",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-router-redux": "^5.0.0-alpha.9",
    "redux": "^4.0.0",
    "redux-thunk": "^2.2.0"
  }

And my setup.

import { AppContainer } from "react-hot-loader";
import React from "react";
import ReactDOM from "react-dom";
import { InMemoryCache } from "apollo-cache-inmemory";
import { ApolloProvider } from "react-apollo";
import ApolloClient from "apollo-boost";
// import { ApolloLink } from "apollo-link";
import { createStore, applyMiddleware, combineReducers } from "redux";
import { Provider } from "react-redux";
import thunk from "redux-thunk";
import { ConnectedRouter, routerMiddleware } from "react-router-redux";
import createHistory from "history/createBrowserHistory";
import * as AbsintheSocket from "@absinthe/socket";
import { createAbsintheSocketLink } from "@absinthe/socket-apollo-link";
import { Socket as PhoenixSocket } from "phoenix";
import reducers from "./js/reducers";
import Application from "./js/Application";
// import "../scss/main.scss";

import absintheSocketLink from "./socketLink";



const history = createHistory();
const appRouterMiddleware = routerMiddleware(history);

const client = new ApolloClient({
  link: absintheSocketLink,
  cache: new InMemoryCache(),
});

const store = createStore(
  combineReducers(reducers),
  {},
  applyMiddleware(appRouterMiddleware, thunk)
);

const render = Component => {
  ReactDOM.render(
    <AppContainer>
      <Provider store={ store }>
        <ApolloProvider client={ client }>
          <ConnectedRouter history={ history }>
            <Component />
          </ConnectedRouter>
        </ApolloProvider>
      </Provider>
    </AppContainer>,
    document.getElementById("root")
  );
};

I stripped some unrelated code, for simplicity.

absintheSocketLink is basically the first example shown. As mentioned this does connect to my socket, but it send my queries to http://localhost:8080/graphql - which i guess is some sort of a fallback.

Is anyone experiencing anything similar? Or am i doing something completely wrong.

@MartinElvar
Copy link
Author

Seems like this error happened as i used Apollo-boosts, replacing it with apollo-client fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant