简体   繁体   English

现有的工作graphQL服务器的中继客户端?

[英]Relay client for existing working graphQL server?

I have working tinySQL GraphQL server running at 127.0.0.1:3000. 我有在127.0.0.1:3000运行的tinySQL GraphQL服务器 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: 它将在React组件中输出如下内容:

{
  "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. 最重要的是,我希望能够设置GraphQL主机IP和端口,也不想更改GraphQL服务器代码中的任何内容。 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? 是否可以在没有babelRelayPlugin.js,babel-relay-plugin,webpack,webpack-dev-server或任何其他魔术的情况下进行此操作?

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? 有可能这样做吗?

As far as I know that is not possible with Relay. 据我所知,Relay无法实现。 You not only need to use Relay's babel plugins, but your server also has to match the Relay GraphQL spec. 您不仅需要使用Relay的babel插件,而且您的服务器还必须匹配Relay GraphQL规范。

However, there are alternatives to Relay that require much less boilerplate, such as Apollo Client or Lokka . 但是,Relay有一些替代方案需要更少的样板,例如Apollo ClientLokka If you're looking for good React integration, then Apollo Client is probably the right choice for what you describe. 如果您正在寻找良好的React集成,那么Apollo Client可能是您所描述的正确选择。

Full disclosure: I am a contributor to Apollo Client 全面披露:我是Apollo Client的撰稿人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM