Hook analog for ApolloError class

92 Views Asked by At

I am refactoring a old component written on React & Apollo client and I have the next pice of code:

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

I've searched through ApolloClient docs and can't find an analog for this class or some example of usage with hooks.

0

There are 0 best solutions below