【发布时间】:2023-04-11 08:01:01
【问题描述】:
我需要帮助来尝试对突变和查询进行打字。文档和示例是有限的,我正在努力理解如何去做。我不太了解文档中的最后一个属性。它似乎是输入,响应,变量,?。 https://www.apollographql.com/docs/react/recipes/static-typing
在我必须使用 any 的地方进行查询和变异:
interface Data {
loading: DataValue<boolean> | undefined;
isLinkValid: DataValue<boolean> | undefined;
}
interface InputProps {
location: {
search: string;
};
showToast: Function;
}
interface Variables {
id: string | string[] | null | undefined;
}
const validateLinkQuery = graphql<InputProps, Data, Variables, Data>(VALIDATE_LINK_MUTATION, {
options: ({ location }) => {
const params = QueryString.parse(location.search);
const id = params.id;
return {
variables: { id },
};
},
props: ({
ownProps,
data,
}: {
ownProps: {
showToast: Function;
};
data?: any;
}) => {
const { validateLink, loading, error } = data;
if (error) {
ownProps.showToast(
Type.ERROR,
get(error, 'graphQLErrors[0].message', 'An error occured on the validate link query')
);
}
return {
isLinkValid: validateLink,
loading,
};
},
});
const validateUserMutation = graphql(
VALIDATE_CARD_MUTATION,
{
props: ({ ownProps, mutate }) => ({
validateCard: (access: SubmitAccessInput) =>
mutate({
variables: {
access,
},
})
.then((response: any) => response)
.catch((error: any) => {
ownProps.showToast(
Type.ERROR,
get(error, 'graphQLErrors[0].message', 'An error occurred while signing up for an account')
);
}),
}),
}
);```
【问题讨论】:
-
无法理解查询或突变的类型定义是什么意思。如果您需要在客户端进行突变和查询的类型定义。它们有很多方法。