0
我有這個簡單的查詢,這在我Graphql工作正常,但我無法通過使用繼電器組件的數據,我不知道爲什麼:(我的查詢失敗,我不知道爲什麼?
{
todolist { // todolist returns array of objects of todo
id
text
done
}
}
這是我在試圖傳遞組件的數據代碼使用繼電器:
class TodoList extends React.Component {
render() {
return <ul>
{this.props.todos.todolist.map((todo) => {
<Todo todo={todo} />
})}
</ul>;
}
}
export default Relay.createContainer(TodoList, {
fragments: {
todos:() => Relay.QL`
fragment on Query {
todolist {
id
text
done
}
}
`,
},
});
而且最後我的架構
const Todo = new GraphQLObjectType({
name: 'Todo',
description: 'This contains list of todos which belong to its\' (Persons)users',
fields:() => {
return {
id: {
type: GraphQLInt,
resolve: (todo) => {
return todo.id;
}
},
text: {
type: GraphQLString,
resolve: (todo) => {
return todo.text;
}
},
done: {
type: GraphQLBoolean,
resolve: (todo) => {
return todo.done;
}
},
}
}
});
const Query = new GraphQLObjectType({
name: 'Query',
description: 'This is the root query',
fields:() => {
return {
todolist: {
type: new GraphQLList(Todo),
resolve: (root, args) => {
return Conn.models.todo.findAll({ where: args})
}
}
}
}
});
此代碼看起來簡單,我不明白爲什麼這是行不通的,我有THI s錯誤Uncaught TypeError: Cannot read property 'todolist' of undefined
,但我配置了todolist,我可以在我的graphql中查詢,你可以看到查詢的結構是一樣的,我不知道爲什麼這不起作用?
我不明白你的大部分代碼,你能推薦我一些資源來閱讀嗎?官方教程太難了:/ –