简体   繁体   English

有没有GraphQL的中继可以使用的方法吗?

[英]Is there way to use Relay without GraphQL?

I'm trying Relay in my React application, and it uses GraphQL by default. 我正在我的React应用程序中尝试Relay,它默认使用GraphQL。 It looks like this ( Score is some React.js component): 看起来像这样( Score是一些React.js组件):

Score = Relay.createContainer(Score, {
    fragments: {
        score: () => Relay.QL`
            fragment on Score {
                initials,
                score,
            }
        `,
    },
});

The question is: can I use custom API functions to return data into fragments? 问题是:我可以使用自定义API函数将数据返回为片段吗? Like this: 像这样:

Score = Relay.createContainer(Score, {
    fragments: {
        score: myCustomFunction(), // It will return a dataset.
    },
});

No, not yet. 还没有。 Support for augmenting the server schema with "local" data is being discussed in this GitHub issue . 在GitHub问题中讨论了使用“本地”数据扩展服务器架构的支持。

In the meantime, you have two options: 同时,您有两个选择:

  • Locate the score computation on the GraphQL server and access it via the schema like you would any other field (note that fields in the schema can be the product of arbitrary computations, so you can do "computed fields" and are not limited to vanilla data-fetching from a secondary store). 在GraphQL服务器上找到分数计算,并通过模式访问它,就像处理其他任何字段一样(请注意,模式中的字段可以是任意计算的乘积,因此您可以执行“计算字段”,而不仅限于原始数据-从二级商店获取)。
  • Locate the data on the client and access it via a side channel apart from GraphQL; 在客户端上找到数据,并通过与GraphQL分开的侧通道访问它们; for example, you could place it in a Flux store and or some other secondary module. 例如,您可以将其放置在Flux商店和/或其他一些辅助模块中。

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

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