我使用reason-apollo并在尝试设置react-native-elements
时遇到问题。我的设置与swapi示例here非常相似。我有一个列表和一个表单,通过变异添加一个新项目。突变成功后,我想重新获取列表中的项目。我创建新项目的代码如下所示(跳过一些不相关的ui代码):
refetchQueries
电影成功添加,我可以在刷新页面时在列表中看到它(使用module CreateFilm = [%graphql
{|
mutation createFilm($name: String!, $favourite: Boolean!, $rating: Int!, $ratedOn: DateTime!) {
createFilm(name: $name, favourite: $favourite, rating: $rating, ratedOn: $ratedOn) {
id
favourite
name
rating
}
}
|}
];
module CreateFilmMutation = ReasonApollo.CreateMutation(CreateFilm);
type state = {
favourite: bool,
rating: int,
};
type action =
| ToggleFavourite
| UpdateRating(int);
let component = ReasonReact.reducerComponent("FilmNew");
let make = _children => {
...component,
initialState: () => {favourite: true, rating: 5},
reducer: action =>
switch (action) {
| ToggleFavourite => (
state => ReasonReact.Update({...state, favourite: ! state.favourite})
)
| UpdateRating(newRating) => (
state => ReasonReact.Update({...state, rating: newRating})
)
},
render: ({state, send}) => {
let now = Js.Date.make() |> Js.Date.toISOString |> Js.Json.string;
let newFilm =
CreateFilm.make(
~name="Temporary test",
~rating=state.rating,
~favourite=state.favourite,
~ratedOn=now,
(),
);
<CreateFilmMutation>
...(
(mutation, _result) =>
<form
onSubmit=(
event => {
ReactEventRe.Synthetic.preventDefault(event);
mutation(
~refetchQueries=[|"allFilms"|],
~variables=newFilm##variables,
(),
)
|> ignore;
}
)>
<input
className="toggle"
_type="checkbox"
checked=state.favourite
onChange=((_) => send(ToggleFavourite))
/>
("is favourite" |> ReasonReact.string)
<input _type="submit" value="Submit" />
</form>
)
</CreateFilmMutation>;
},
};
查询)。但allFilms
似乎没有任何效果。我的后端使用的是graph.cool,类似于docs中的swapi示例。感谢任何帮助,谢谢!
答案 0 :(得分:0)
问题不在于变异,而是在我想要重新获取的查询中 - 它缺少了graphql操作名称♂️