For simplicity's sake, we will implement this mutation in a new component and a new URL.
So, first, let's add a link to this new page in the router (in src/App.js):
<Route path="/user/:login/addrepo" component={AddRepository} />
We also need to add the possibility for the user to reach that page by adding a link to our new page at the end of the repository list of the User component (src/components/User.js):
<li><Link to={`/user/${login}/addrepo`}>Add new repository</Link></li>
Then, we can create the AddRepository component in src/components/AddRepository.js. First, let's define the mutation in terms of GraphQL:
const CREATE_REPO = gql`
mutation($name: String!, $login: String!) {
CreateRepository(name: $name) {
name
}
AddRepositoryOwner(from: { login: $login }, to: { name: $name }) {
from {
login
}
to {
name
}
}
}
`;
Similar to what we have done for queries, we will create a mutation with two variables...