import React from 'react';
import { ApolloClient, HttpLink, InMemoryCache, ApolloProvider } from '@apollo/client';

const baseUrl = window.location.origin;

const defaultHttpLink = new HttpLink({
    uri: `${baseUrl}/api/graphql/preview`
});

const client = new ApolloClient({
    cache: new InMemoryCache(),
    link: defaultHttpLink
});

// eslint-disable-next-line no-unused-vars
const withGraphQLGeneric = WrappedComponent => {
    const GraphQLClient = props => (
        <ApolloProvider client={client}>
            <WrappedComponent
                {...props}
            />
        </ApolloProvider>
    );
    return GraphQLClient;
};

export default withGraphQLGeneric;
