现有的工作graphQL服务器的中继客户端? [英] Relay client for existing working graphQL server?

查看:64
本文介绍了现有的工作graphQL服务器的中继客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有运行 tinySQL GraphQL服务器,运行于127.0.0.1:3000.我想为其创建任何可用的中继客户端.我的意思是查询的任何可行示例:

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
  }
}

将会在React组件中输出如下内容:

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"
      }
    ]
  }
} 

最重要的是我希望能够设置GraphQL主机IP和端口,也不想更改GraphQL服务器代码中的任何内容.有可能做到吗?可以不用babelRelayPlugin.js,babel-relay-plugin,webpack,webpack-dev-server或任何其他魔术来做到吗?

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?

我的意思是:

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?

推荐答案

据我所知,Relay无法实现.您不仅需要使用Relay的babel插件,而且您的服务器还必须匹配Relay GraphQL规范.

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.

但是,中继的替代方法却需要更少的样板,例如 Apollo客户端 Lokka .如果您正在寻找良好的React集成,那么Apollo Client可能就是您所描述的正确选择.

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.

全部披露:我是Apollo Client的撰稿人

Full disclosure: I am a contributor to Apollo Client

这篇关于现有的工作graphQL服务器的中继客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆