React Native
...
Users
Working with Users
8 min
working with users introduction at the core of many apps, user accounts have a notion that lets users securely access their information at back4app/parse provides a specialized user class called parse user that automatically handles much of the functionality required for user account management we will better explain how this class works by giving you a practical guide on making a user sign up, a user log in, and a user logout in the next tutorials, let’s understand how to implement each one in a react native application using graphql and relay goal explain the parse user class and how relay will handle with this class parse user class parse user is a subclass of parse object, and has all the same features, such as flexible schema, automatic persistence, and a key value interface all the methods on parse object also exist in parse user the difference is that parse user has some special additions specific to user accounts parse user properties parse user has several values that set it apart from parse object username the username for the user (required) password the password for the user (required on signup) email the email address for the user (optional) we’ll go through each of these in detail as we run through the various use cases for users relay mutation a way to handle the user class on a front end with relay in react native is using mutations mutations are responsible for creating functions, executing them, sending the data to the backend, and expecting a return any mutation function will prepare the data to send it when returned from the backend, handle the success or error scenario in both cases, the application can control the next state and decide what will happen after this guide is using relay modern on the frontend to consume graphql the flow to create a mutation is similar to create a query or fragment the relay mutation needs to be equal to the backend specification when creating a new mutation, the relay compiler will check if the backend structure is identical to the application/frontend source of truth, the schema graphql every relay mutation will have a principal function called commitmutation this function handles the graphql fragment, the input variables, the completed, and the error callback the relay mutation can have other arguments, but in the next tutorials won’t be used commitmutation commitmutation is the default function to create and execute mutations in your graphql on the client side similar to queryrenderer, the commitmutation will receive props these props, combine in themselves, will prepare the fetch, call the server, and handle the return there so many props to handle your application on each case that it needs but, in the next tutorials, it will use only the next one environment the environment is responsible for the store and network of applications input is an object that contains the variables necessary to resolve the mutation oncompleted and onerror are functions, as the name says, called when the mutation is complete the oncompleted is for success and onerror for error example of commitmutation 1 function commit({environment, input, oncompleted, onerror}) { 2 const variables = {input}; 3	 4 commitmutation(environment, { 5 mutation, 6 variables, 7 oncompleted, 8 onerror, 9 }); 10 } 11	 12 export default { 13 commit, for more info about relay mutation go to the official docs conclusion now, the mutation concept is clear and explained in the next tutorial, it will handle the sign up flow on back4app there it will be specified how to implement a simple mutation to register a new user and return a session token