Add join team mutation to client

This commit is contained in:
Ramon Wenger 2021-03-25 23:13:31 +01:00
parent 58e5eb1617
commit 07071148e3
1 changed files with 28 additions and 4 deletions

View File

@ -11,6 +11,9 @@
</template>
<script>
import JOIN_TEAM_MUTATION from '@/graphql/gql/mutations/joinTeam.gql';
import ME_QUERY from '@/graphql/gql/meQuery.gql';
import JoinForm from '@/components/profile/JoinForm';
import {MY_TEAM} from '@/router/me.names';
@ -24,8 +27,8 @@
code: '',
error: '',
teamRoute: {
name: MY_TEAM
}
name: MY_TEAM,
},
};
},
@ -38,8 +41,29 @@
this.$router.push(this.teamRoute);
},
joinTeam(code) {
// todo
console.log('joinTeam', code);
this.$apollo.mutate({
mutation: JOIN_TEAM_MUTATION,
variables: {
'input': {
'code': code,
},
},
update: (store, {data: {joinTeam: {team}}}) => {
const query = ME_QUERY;
const data = store.readQuery({query});
store.writeQuery({
query,
data: {
...data,
me: {
...data.me,
team: team,
},
},
});
this.$router.push({name: MY_TEAM});
},
});
},
},
};