How to use the react-apollo.useApolloClient function in react-apollo

To help you get started, we’ve selected a few react-apollo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / webiny-js / packages / app-page-builder / src / admin / plugins / pageDetails / utils / usePublishRevisionHandler.js View on Github external
export function usePublishRevisionHandler({ page }) {
    const client = useApolloClient();
    const { showSnackbar } = useSnackbar();

    const publishRevision = async revision => {
        const { data: res } = await client.mutate({
            mutation: PUBLISH_REVISION,
            variables: { id: revision.id },
            refetchQueries: ["PbListPages"],
            update: (cache, { data }) => {
                // Don't do anything if there was an error during publishing!
                if (data.pageBuilder.publishRevision.error) {
                    return;
                }

                const getPageQuery = GET_PAGE();

                // Update revisions
github webiny / webiny-js / packages / app-admin / src / components / Install / Install.js View on Github external
const Install = ({ plugins, children, security }) => {
    const client = useApolloClient();
    const [ready, setReady] = useState(false);
    const [login, setLogin] = useState(false);
    const [user, setUser] = useState(null);
    const [current, setCurrentInstaller] = useState(null);
    const toInstall = useRef([]);
    const graph = useRef(null);

    const onUser = user => {
        setUser(user);
        setLogin(false);
        console.log("onUser", user);
    };

    const nextInstaller = () => {
        const currentIndex = !current
            ? -1
github webiny / webiny-js / packages / app-admin / src / components / FileManager / FileDetails / Name.js View on Github external
function Name({ file }: *) {
    const [editing, setEdit] = useState(false);
    const name = file.name || "";

    const { showSnackbar } = useSnackbar();
    const client = useApolloClient();

    const { queryParams } = useFileManager();

    if (editing) {
        return (
            <form name=""> {
                    setEdit(false);
                    await client.mutate({
                        mutation: UPDATE_FILE,
                        variables: {
                            id: file.id,
                            data: { name }</form>
github webiny / webiny-js / packages / app-security / src / admin / views / Account.js View on Github external
.pop();

    if (!auth) {
        throw Error(
            `You must register a "security-authentication-provider" plugin to render Account form!`
        );
    }

    const { renderUserAccountForm } = auth;

    const [{ loading, user }, setState] = useReducer((prev, next) => ({ ...prev, ...next }), {
        loading: true,
        user: { data: {} }
    });

    const client = useApolloClient();
    const { showSnackbar } = useSnackbar();
    const security = useSecurity();

    const onSubmit = useHandler(null, () => async formData => {
        setState({ loading: true });
        const { data: response } = await client.mutate({
            mutation: UPDATE_CURRENT_USER,
            variables: { data: omit(formData, ["id"]) }
        });
        const { error } = response.security.updateCurrentUser;
        setState({ loading: false });
        if (error) {
            return showSnackbar(error.message, {
                actionText: "Close"
            });
        }
github webiny / webiny-js / packages / app-page-builder / src / admin / plugins / pageDetails / header / editRevision / EditRevision.js View on Github external
const EditRevision = () => {
    const { showSnackbar } = useSnackbar();
    const client = useApolloClient();
    const { history } = useReactRouter();
    const { page } = usePageDetails();

    const unpublishedRevision = (get(page, "revisions") || []).find(
        item => !item.published && !item.locked
    );

    const editRevision = useCallback(() => {
        if (unpublishedRevision) {
            history.push(`/page-builder/editor/${unpublishedRevision.id}`);
        }
    });

    const copyAndEdit = useCallback(async () => {
        const [latestRevision] = page.revisions;
        const { data: res } = await client.mutate({
github webiny / webiny-js / packages / app-admin / src / components / FileManager / FileDetails / Tags.js View on Github external
function Tags({ file }) {
    const client = useApolloClient();

    const [editing, setEdit] = useState(false);
    const [saving, setSaving] = useState(false);
    const initialTags = Array.isArray(file.tags) ? [...file.tags] : [];
    const [currentTags, setCurrentTags] = useState(initialTags);
    const { showSnackbar } = useSnackbar();

    const { queryParams } = useFileManager();

    if (editing) {
        return (
            &lt;&gt;
github OriginProtocol / origin / dapps / marketplace / src / pages / nav / Profile.js View on Github external
const ProfileDropdownRaw = ({
  walletProxy,
  wallet,
  data,
  identity,
  identityLoaded,
  onClose,
  onRewardsClick
}) =&gt; {
  const { id } = data.web3.primaryAccount
  const address = `ETH Address: ${formatHash(wallet)}`
  const devMode = store.get('developerMode')

  const client = useApolloClient()
  const [logout] = useMutation(LogoutMutation, {
    variables: { wallet }
  })

  return (
    &lt;&gt;
      <div>
      <div>
        <a href="#close"> {
            e.preventDefault()
            onClose()
          }}
        &gt;</a></div></div>
github webiny / webiny-js / packages / app-i18n / src / admin / plugins / install.js View on Github external
const I18NInstaller = ({ onInstalled }) => {
    const client = useApolloClient();
    const [loading, setLoading] = useState(false);
    const [error, setError] = useState(null);

    const onSubmit = useCallback(async form => {
        setLoading(true);
        setError(null);
        const { data: res } = await client.mutate({ mutation: INSTALL, variables: { data: form } });
        setLoading(false);
        const { error } = res.i18n.install;
        if (error) {
            setError(error.message);
            return;
        }

        onInstalled();
    }, []);
github webiny / webiny-js / packages / app-page-builder / src / admin / plugins / pageDetails / header / deletePage / DeletePage.js View on Github external
const DeletePage = props =&gt; {
    const client = useApolloClient();
    const { showSnackbar } = useSnackbar();
    const { history } = useReactRouter();
    const { showDialog } = useDialog();

    const title = get(props, "pageDetails.page.title", "N/A");

    const { showConfirmation } = useConfirmationDialog({
        title: "Delete page",
        message: (
            <p>
                You are about to delete the entire page and all of its revisions! <br>
                Are you sure you want to permanently delete the page <strong>{title}</strong>?
            </p>
        )
    });
github webiny / webiny-js / packages / app-security / src / admin / plugins / installation.js View on Github external
const Install = ({ onInstalled }) => {
    const auth = getPlugins("security-authentication-provider")
        .filter(pl => pl.hasOwnProperty("renderInstallForm"))
        .pop();

    if (!auth) {
        throw Error(`You must register a "security-authentication-provider" plugin!`);
    }

    const { renderInstallForm } = auth;

    const client = useApolloClient();
    const [loading, setLoading] = useState(false);
    const [authUserMessage, setAuthUserMessage] = useState(null);
    const [error, setError] = useState(null);

    const onSubmit = useCallback(async form => {
        setLoading(true);
        setError(null);
        const { data: res } = await client.mutate({ mutation: INSTALL, variables: { data: form } });
        setLoading(false);
        const { error, data } = res.security.install;
        if (error) {
            setError(error);
            return;
        }

        if (!data.authUser) {