How to use the react-relay.Store function in react-relay

To help you get started, weโ€™ve selected a few react-relay 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 papigers / question-it / shared / components / registerForm / RegisterForm.jsx View on Github external
submit = (e) => {
    e.preventDefault();
    this.setState({ pressed: true });
    this.validate.forEach(el => el._reactInternalInstance._renderedComponent._instance.validate()); // eslint-disable-line no-underscore-dangle, max-len
    if (this.state.maxValid !== this.state.numValid) {
      return;
    }
    const { username, email, password } = this.state;
    Relay.Store.commitUpdate(new RegisterUserMutation({ username, email, password }), {
      onSuccess: ({ registerUser: res }) => {
        if (res.error) {
          this.setState({ error: res.error });
          return;
        }

        this.setState({ error: '' });

        fetch('/login/local', {
          method: 'POST',
          headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
          },
          credentials: 'same-origin',
          body: JSON.stringify({
github rodrigopivi / PlayApp / src / client / networkLayer.ts View on Github external
return new Promise((resolve, reject) => {
            // Note: tried to use primeCache, works fine for the first req, but fails for the 2nd
            // (Relay.Store as any).primeCache({query: request._query}, readyState => {
            let data: any[] = []
            let cachedData = (Relay.Store as any).readQuery(request._query)
            if (cachedData && cachedData.length && cachedData[0] && cachedData[0].recentMessages) {
                const messagesToPush = pushMessagesStore.getState().messagesToPush
                data = data.concat(cachedData[0].recentMessages).concat(messagesToPush)
                pushMessagesStore.dispatch({ type: 'CLEAR_MESSAGES'})
                const response = { 'data': { 'root': { 'recentMessages': data } } }
                const jsonResponsePromise = new Promise((res) => {
                    res({ json: () => { return response } })
                })
                resolve(jsonResponsePromise)
            } else {
                resolve(super._sendQuery(request))
            }
        })
    }
github gauravtiwari / relay-rails-blog / client / app / bundles / PostsIndex / components / Posts.jsx View on Github external
_handleCreatePost(data) {
    Relay.Store.commitUpdate(new PostMutations({
      viewer: this.props.root,
      data: data,
    }), {onFailure, onSuccess});

    const _this = this;

    const onSuccess = () => {
      _this.setState({
        formToggled: false,
      });
    };

    const onFailure = (transaction) => {
      const error = transaction.getError() || new Error('Mutation failed.');
      console.error(error);
      _this.setState({
github ticruz38 / Ambrosia / client / components / board / settings.js View on Github external
var resto = restaurant.toJS();
    delete resto.__dataID__;
    delete resto.orders;
    resto.schedule.map(object => {
      delete object.__dataID__;
      object.openHours.map(op => delete op.__dataID__);
    });
    console.log('resto', resto);
    var onFailure = () => {
      console.log('onFailure');
    };
    var onSuccess = () => {
      console.log('onSuccess');
      this.setState({save: false});
    };
    Relay.Store.commitUpdate(new UpdateRestaurantMutation({restaurant: resto}), {onFailure, onSuccess});
  };
  //
github ticruz38 / Ambrosia / client / components / index.js View on Github external
_logout = () => {
    console.log('LoginButton:Logout', this.props);
    //the easiest way to logout is to login with unknown user
    Relay.Store.update(new LoginMutation({credentials: {pseudo:'', password:''}, user: this.props}));
  };
  _expand = () => {
github learnapollo / learnapollo / src / components / ServerLayover / ServerLayover.tsx View on Github external
render() {
    return (
       Relay.QL`query { viewer }`},
          params: {projectId: this.props.projectId, close: this.props.close},
        }}
      />
    )
  }
}
github reindexio / reindex-examples / todomvc-single-user / src / components / TodoApp.js View on Github external
      .forEach((edge) => Relay.Store.commitUpdate(
        new DeleteTodoMutation({
          id: edge.node.id,
          viewer: this.props.viewer,
        })
      ));
  };
github reindexio / reindex-examples / todomvc-single-user / src / components / TodoApp.js View on Github external
handleInputSave = (text) => {
    Relay.Store.commitUpdate(
      new AddTodoMutation({
        text,
        viewer: this.props.viewer,
      }),
    );
  }
github scaphold-io / react-relay-starter-kit / js / auth / Auth.js View on Github external
return new Promise((resolve, reject) => {
    Relay.Store.commitUpdate(new RegisterMutation({
      input: {
        username: username,
        password: password
      },
      user: null
    }), {
      onSuccess: (data) => {
        resolve(login(username, password));
      },
      onFailure: (transaction) => {
        reject(transaction.getError().message);
      }
    });
  })
}
github gauravtiwari / relay-rails-blog / client / app / bundles / Comments / components / Comment.jsx View on Github external
_saveComment(event) {
    event.preventDefault();
    if (!this.props.comment.is_owner) return;

    const onFailure = (transaction) => {
      const error = transaction.getError() || new Error('Mutation failed.');
      alert(error);
    };

    const onSuccess = () => {
      this.setState({ editing: false });
    };

    if (event.keyCode === 13) {
      Relay.Store.commitUpdate(new EditComment({
        id: this.props.comment.id,
        body: event.target.value,
      }), { onFailure, onSuccess });
    }
  }