简体   繁体   English

连接到Github的GraphQL时Relay和ReactJS给出错误

[英]Relay and ReactJS give an error when connecting to Github's GraphQL

Using a Relay Container and Github's GraphQL API if I have fragment on User { id } it successfully loads my github account id . 如果我fragment on User { id }fragment on User { id }使用中继容器Github的GraphQL API ,它将成功加载我的github帐户id。 However if I try fragment on Repository {} it says "GraphQL unknown type". 但是,如果我尝试fragment on Repository {}则会显示“ GraphQL未知类型”。

What is the best way to reliably query fragments from GitHub's API using Relay? 使用Relay从GitHub API可靠查询片段的最佳方法是什么?

I was getting the error because graphQL has specific properties accessible to the client. 我收到错误消息是因为graphQL具有客户端可以访问的特定属性。 Trying to fetch an erroneous fragment (or in my case incorrectly nested fragment names) results in "GraphQL unknown type". 尝试获取错误的片段(在我的情况下,错误地嵌套了片段名称)会导致“ GraphQL未知类型”。 The solution is to use Github's GraphQL root node called relay which re-exposes all root queries such as repository see the docs for more details. 解决方案是使用Github的称为relay的GraphQL根节点,该节点重新公开所有根查询,例如repository 有关更多详细repository请参阅文档 Here is my parent query: 这是我的父查询:

 import Relay from 'react-relay' export default { relay : Component => Relay.QL ` query { relay { ${Component.getFragment('relay')} } } ` }; 

and here is my container component 这是我的容器组件

 import Relay from 'react-relay' import App from './AppComponent' export default Relay.createContainer(App, { initialVariables: { owner: "rails", name: "rails", count: 10 }, fragments: { relay: () => Relay.QL ` fragment on Query { repository(owner: $owner, name: $name) { name owner description issues(first: 20) { edges { node { title } } } } }` } }); 

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

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