How to use the @apollo/react-hooks.useMutation function in @apollo/react-hooks

To help you get started, we’ve selected a few @apollo/react-hooks 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 ian13456 / mine.js / src / components / Forms / LoginForm / LoginForm.js View on Github external
const LoginForm = ({ history, loading: authLoading }) => {
  const client = useApolloClient()

  const [login, { error, loading }] = useMutation(LOGIN_MUTATION, {
    onCompleted: data => {
      setCookie(data.login.token)

      // Force a reload of all current queries now that user is
      // logged in
      client.cache.reset().then(() => {
        history.push('/home')
      })
    },
    onError: err => console.error(err)
  })

  if (loading || authLoading) {
    return 
  }
github VulcanJS / Vulcan / packages / vulcan-core / lib / modules / containers / delete2.js View on Github external
export const useDelete2 = (options) => {
  const { collectionName, collection } = extractCollectionInfo(options);
  const { fragmentName, fragment } = extractFragmentInfo(options, collectionName);
  const typeName = collection.options.typeName;
  const {
    //input: optionsInput,
    //_id: optionsId,
    mutationOptions = {},
  } = options;

  const query = buildDeleteQuery({
    fragment,
    fragmentName, typeName
  });

  const [deleteFunc, ...rest] = useMutation(query, {
    // optimistic update
    update: multiQueryUpdater({ collection, typeName, fragment, fragmentName }),
    ...mutationOptions
  });
  const extendedDeleteFunc = (args/*{ input: argsInput, _id: argsId }*/) => {
    return deleteFunc({
      variables: {
        ...computeQueryVariables(options, args)
      }
    });
  };
  return [extendedDeleteFunc, ...rest];
};
github karanpratapsingh / Proximity / app / screens / NotificationScreen / components / NotificationCard.tsx View on Github external
const NotificationCard: React.FC = ({ notificationId, avatar, resourceId, handle, type, time }) => {

  const { theme } = useContext(AppContext);
  const { navigate } = useNavigation();
  const notificationText = NotificationText[type];
  const { readableTime } = parseTimeElapsed(time);

  const [deleteNotification, { loading: deleteNotificationLoading, called: deleteNotificationCalled }] = useMutation(MUTATION_DELETE_NOTIFICATION);

  const swipeableRef = useRef();

  const navigateAction = () => {
    if (resourceId === '') return;

    if (type === NotificationType.FOLLOW) {
      navigate(Routes.ProfileViewScreen, { userId: resourceId });
    } else if (type === NotificationType.LIKE || type === NotificationType.COMMENT) {
      navigate(Routes.PostViewScreen, { postId: resourceId });
    }
  };

  const onDelete = () => {
    if (!deleteNotificationLoading && !deleteNotificationCalled) {
      // @ts-ignore
github nemanjam / rn-chat / client / src / screens / LoginScreen.js View on Github external
const LoginScreen = props => {
  //const [showToast, setShowToast] = useState(false);
  const [login, { ...mutationResult }] = useMutation(LOGIN_MUTATION);

  async function formSubmit(values) {
    const { data } = await login({
      variables: {
        email: values.email,
        password: values.password,
      },
    });
    const user = data.login;
    props.setCurrentUser(user);
    props.navigation.navigate('Home');
  }

  if (mutationResult.loading) return ;
  if (mutationResult.error) {
    Toast.show({
github kyma-project / console / core-ui / src / components / CreateNamespaceForm / CreateNamespaceForm.js View on Github external
enableContainerLimits: useRef(null),
      max: useRef(null),
      default: useRef(null),
      defaultRequest: useRef(null),
    },
  };
  useEffect(() => {
    const element = formValues.name.current;
    setImmediate(() => {
      if (element && typeof element.focus === 'function') element.focus();
    });
  }, [formValues.name]);

  const [createNamespaceMutation] = useMutation(CREATE_NAMESPACE);
  const [createLimitRangeMutation] = useMutation(CREATE_LIMIT_RANGE);
  const [createResourceQuotaMutation] = useMutation(CREATE_RESOURCE_QUOTA);

  function handleLabelsChanged(newLabels) {
    setLabels(newLabels);
  }

  function handleIstioChange(disableSidecar) {
    const [istioInjLabelKey, istioInjLabelValue] = ISTIO_INJECTION_LABEL.split(
      '=',
    );

    if (disableSidecar) {
      setReadonlyLabels({
        ...readonlyLabels,
        [istioInjLabelKey]: istioInjLabelValue,
      });
    } else {
github cube-js / cube.js / packages / cubejs-server-core / dev / templates / packages / react-antd-dynamic / scaffolding / src / components / TitleModal.js View on Github external
itemId,
  titleModalVisible,
  setTitleModalVisible,
  setAddingToDashboard,
  finalVizState,
  setTitle,
  finalTitle
}) => {
  const [addDashboardItem] = useMutation(CREATE_DASHBOARD_ITEM, {
    refetchQueries: [
      {
        query: GET_DASHBOARD_ITEMS
      }
    ]
  });
  const [updateDashboardItem] = useMutation(UPDATE_DASHBOARD_ITEM, {
    refetchQueries: [
      {
        query: GET_DASHBOARD_ITEMS
      }
    ]
  });

  return (
     {
        setTitleModalVisible(false);
        setAddingToDashboard(true);
github thewca / wca-live / client / src / components / admin / AdminDashboard / AdminDashboard.js View on Github external
const AdminDashboard = ({ me, history }) => {
  const classes = useStyles();
  const apolloClient = useApolloClient();
  const [signOut, { loading, error }] = useMutation(SIGN_OUT_MUTATION, {
    onCompleted: data => {
      apolloClient.clearStore().then(() => history.push('/'));
    },
  });
  const { name, avatar, manageableCompetitions, importableCompetitions } = me;

  return (
    
      
        
          
        
        
          Hello, {name}!
github guildspeak / guildspeak-desktop / src / renderer / views / Application / index.tsx View on Github external
const Application = ({ channelId, guildId }: Props & RouteComponentProps) => {
  const [updateUserStatus] = useMutation(UPDATE_USER_STATUS)

  const updateStatus = () => {
    if (!document.hidden && document.visibilityState === 'visible' && navigator.onLine) {
      return updateUserStatus({ variables: { lastSeen: dayjs().toISOString() } })
    }
  }

  useEffect(() => {
    document.addEventListener('visibilitychange', updateStatus)
    return () => document.removeEventListener('visibilitychange', updateStatus)
  }, [updateStatus])

  useEffect(() => {
    const interval = setInterval(updateStatus, 30000)
    return () => clearInterval(interval)
  }, [])
github reactioncommerce / reaction / imports / plugins / included / product-admin / client / hocs / withProduct.js View on Github external
function WithProduct(props) {
    const { history } = props;
    const [cloneProducts] = useMutation(CLONE_PRODUCTS);
    const [createProductVariant] = useMutation(CREATE_VARIANT);

    return (
       {
          await handleArchiveProduct(product);
          history.push(redirectUrl);
        }}
        onCloneProduct={async (product) => {
          const opaqueProductIds = await getOpaqueIds([{ namespace: "Product", id: product }]);
          const [opaqueShopId] = await getOpaqueIds([{ namespace: "Shop", id: Reaction.getShopId() }]);

          try {
            await cloneProducts({ variables: { input: { shopId: opaqueShopId, productIds: opaqueProductIds } } });
            Alerts.toast(i18next.t("productDetailEdit.cloneProductSuccess"), "success");
          } catch (error) {
            Alerts.toast(i18next.t("productDetailEdit.cloneProductFail", { err: error }), "error");
github karanpratapsingh / Proximity / app / screens / ProfileScreen / components / EditProfileBottomSheet.tsx View on Github external
const { user, updateUser: updateUserContext, theme } = useContext(AppContext);

  const [editableAvatar, setEditableAvatar] = useState('');
  const [editableName, setEditableName] = useState('');
  const [editableHandle, setEditableHandle] = useState('');
  const [handleError, setHandleError] = useState('');
  const [editableAbout, setEditableAbout] = useState('');
  const [isUploading, setIsUploading] = useState(false);

  const [queryIsHandleAvailable, {
    loading: isHandleAvailableLoading,
    called: isHandleAvailableCalled,
    data: isHandleAvailableData
  }] = useLazyQuery(QUERY_HANDLE_AVAILABLE);

  const [updateUser] = useMutation(MUTATION_UPDATE_USER);

  useEffect(() => {
    setEditableAvatar(avatar);
    setEditableName(name);
    setEditableHandle(handle);
    setEditableAbout(about);
  }, []);

  useEffect(() => {
    queryIsHandleAvailable({
      variables: {
        userId: user.id,
        handle: editableHandle
      }
    });
  }, [editableHandle]);