Relay client for existing working graphQL server?

六眼飞鱼酱① 提交于 2019-12-12 02:34:31

问题


I have working tinySQL GraphQL server running at 127.0.0.1:3000. I would like to create any working Relay client for it. I mean any working example for query:

{
  groupBy (age: 20, job: "student") {
    id,
    name,
    age,
    job
  }
}

that will output in React component something like that:

{
  "data": {
    "groupBy": [
      {
        "id": 1,
        "name": "Marie",
        "age": 20,
        "job": "student"
      },
      {
        "id": 5,
        "name": "Jessie",
        "age": 20,
        "job": "student"
      }
    ]
  }
} 

Most important thing is I want to be able to set GraphQL host IP and port and also don't want to change anything in GraphQL server code. Is it possible to do it? Is it possible to do it without babelRelayPlugin.js, babel-relay-plugin, webpack, webpack-dev-server or any other magic tricks?

EDIT:

I mean:

class App extends React.Component {
  render() {
    return (
      <div>
      // Simple example here?
      </div>
    );
  }
}

Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer('http://127.0.0.1:3000')
);

const AppContainer = Relay.createContainer(App, {
  // Simple example here?
});

ReactDOM.render(
  // Simple example here?
);

Anyone? Is it possible to do it like this?


回答1:


As far as I know that is not possible with Relay. You not only need to use Relay's babel plugins, but your server also has to match the Relay GraphQL spec.

However, there are alternatives to Relay that require much less boilerplate, such as Apollo Client or Lokka. If you're looking for good React integration, then Apollo Client is probably the right choice for what you describe.

Full disclosure: I am a contributor to Apollo Client



来源:https://stackoverflow.com/questions/37688952/relay-client-for-existing-working-graphql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!