1

我正在重构一个在 React 和 Apollo 客户端上编写的旧组件,我有下一段代码:

export const getBusiness = (query: DocumentNode) => compose([
    graphql<BusinessSchema, BusinessPartnerSchema, Identity, GQLResult<LegalEntity> | undefined>(query, {
        options: props => ({
            variables: { id }
        }),
        props: ({ data }) => data && Object.assign(
            { loading: data.loading, error: data.error || validateLegalEntity(data.businessPartner) },
            data.businessPartner && {
                prop: data.prop
            }
        ),
        skip: props => !props.id
    })
]

)

const validateBusiness = (data?: BusinessUnit): ApolloError | undefined =>
     data && data.businessPartners.length === 0 &&
     new ApolloError({
     graphQLErrors: [{ message: 'User has no assigned outlets', extensions: { business: 'validation' } } as unknown as GraphQLError]
     }) || undefined

我搜索了 ApolloClient 文档,但找不到此类的模拟或使用钩子的一些示例。

4

0 回答 0