Merge pull request #863 from gradido/queries-to-mutations

refactor: Queries to Mutations
This commit is contained in:
Moriz Wahl 2021-09-23 20:46:04 +02:00 committed by GitHub
commit 823b4a1efc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 115 additions and 112 deletions

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Resolver, Query, Args, Authorized, Ctx } from 'type-graphql'
import { Resolver, Query, Args, Authorized, Ctx, Mutation } from 'type-graphql'
import CONFIG from '../../config'
import { TransactionList } from '../models/Transaction'
import { TransactionListInput, TransactionSendArgs } from '../inputs/TransactionInput'
@ -23,7 +23,7 @@ export class TransactionResolver {
}
@Authorized()
@Query(() => String)
@Mutation(() => String)
async sendCoins(
@Args() { email, amount, memo }: TransactionSendArgs,
@Ctx() context: any,

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware } from 'type-graphql'
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
import CONFIG from '../../config'
import { CheckUsernameResponse } from '../models/CheckUsernameResponse'
import { LoginViaVerificationCode } from '../models/LoginViaVerificationCode'
@ -66,8 +66,8 @@ export class UserResolver {
return 'success'
}
@Query(() => String)
async create(
@Mutation(() => String)
async createUser(
@Args() { email, firstName, lastName, password, language }: CreateUserArgs,
): Promise<string> {
const payload = {
@ -104,7 +104,7 @@ export class UserResolver {
return new SendPasswordResetEmailResponse(response.data)
}
@Query(() => String)
@Mutation(() => String)
async resetPassword(
@Args()
{ sessionId, email, password }: ChangePasswordArgs,
@ -122,7 +122,7 @@ export class UserResolver {
}
@Authorized()
@Query(() => UpdateUserInfosResponse)
@Mutation(() => UpdateUserInfosResponse)
async updateUserInfos(
@Args()
{

View File

@ -3,7 +3,7 @@ import LanguageSwitch from './LanguageSwitch'
const localVue = global.localVue
const updateUserInfosQueryMock = jest.fn().mockResolvedValue({
const updateUserInfosMutationMock = jest.fn().mockResolvedValue({
data: {
updateUserInfos: {
validValues: 1,
@ -28,7 +28,7 @@ describe('LanguageSwitch', () => {
locale: 'en',
},
$apollo: {
query: updateUserInfosQueryMock,
mutate: updateUserInfosMutationMock,
},
}
@ -119,7 +119,7 @@ describe('LanguageSwitch', () => {
describe('calls the API', () => {
it("with locale 'en'", () => {
wrapper.findAll('li').at(0).find('a').trigger('click')
expect(updateUserInfosQueryMock).toBeCalledWith(
expect(updateUserInfosMutationMock).toBeCalledWith(
expect.objectContaining({
variables: {
email: 'he@ho.he',
@ -131,7 +131,7 @@ describe('LanguageSwitch', () => {
it("with locale 'de'", () => {
wrapper.findAll('li').at(1).find('a').trigger('click')
expect(updateUserInfosQueryMock).toBeCalledWith(
expect(updateUserInfosMutationMock).toBeCalledWith(
expect.objectContaining({
variables: {
email: 'he@ho.he',

View File

@ -14,7 +14,7 @@
<script>
import { localeChanged } from 'vee-validate'
import locales from '../locales/'
import { updateUserInfos } from '../graphql/queries'
import { updateUserInfos } from '../graphql/mutations'
export default {
name: 'LanguageSwitch',
@ -36,8 +36,8 @@ export default {
this.setLocale(locale)
if (this.$store.state.email) {
this.$apollo
.query({
query: updateUserInfos,
.mutate({
mutation: updateUserInfos,
variables: {
email: this.$store.state.email,
locale: locale,

View File

@ -11,3 +11,59 @@ export const unsubscribeNewsletter = gql`
unsubscribeNewsletter(email: $email)
}
`
export const resetPassword = gql`
mutation($sessionId: Float!, $email: String!, $password: String!) {
resetPassword(sessionId: $sessionId, email: $email, password: $password)
}
`
export const updateUserInfos = gql`
mutation(
$email: String!
$firstName: String
$lastName: String
$description: String
$username: String
$password: String
$passwordNew: String
$locale: String
) {
updateUserInfos(
email: $email
firstName: $firstName
lastName: $lastName
description: $description
username: $username
password: $password
passwordNew: $passwordNew
language: $locale
) {
validValues
}
}
`
export const registerUser = gql`
mutation(
$firstName: String!
$lastName: String!
$email: String!
$password: String!
$language: String!
) {
createUser(
email: $email
firstName: $firstName
lastName: $lastName
password: $password
language: $language
)
}
`
export const sendCoins = gql`
mutation($email: String!, $amount: Float!, $memo: String!) {
sendCoins(email: $email, amount: $amount, memo: $memo)
}
`

View File

@ -22,12 +22,6 @@ export const logout = gql`
}
`
export const resetPassword = gql`
query($sessionId: Float!, $email: String!, $password: String!) {
resetPassword(sessionId: $sessionId, email: $email, password: $password)
}
`
export const loginViaEmailVerificationCode = gql`
query($optin: String!) {
loginViaEmailVerificationCode(optin: $optin) {
@ -37,32 +31,6 @@ export const loginViaEmailVerificationCode = gql`
}
`
export const updateUserInfos = gql`
query(
$email: String!
$firstName: String
$lastName: String
$description: String
$username: String
$password: String
$passwordNew: String
$locale: String
) {
updateUserInfos(
email: $email
firstName: $firstName
lastName: $lastName
description: $description
username: $username
password: $password
passwordNew: $passwordNew
language: $locale
) {
validValues
}
}
`
export const transactionsQuery = gql`
query($firstPage: Int = 1, $items: Int = 25, $order: String = "DESC") {
transactionList(firstPage: $firstPage, items: $items, order: $order) {
@ -94,30 +62,6 @@ export const transactionsQuery = gql`
}
`
export const resgisterUserQuery = gql`
query(
$firstName: String!
$lastName: String!
$email: String!
$password: String!
$language: String!
) {
create(
email: $email
firstName: $firstName
lastName: $lastName
password: $password
language: $language
)
}
`
export const sendCoins = gql`
query($email: String!, $amount: Float!, $memo: String!) {
sendCoins(email: $email, amount: $amount, memo: $memo)
}
`
export const sendResetPasswordEmail = gql`
query($email: String!) {
sendResetPasswordEmail(email: $email) {

View File

@ -25,7 +25,7 @@ describe('AccountOverview', () => {
},
},
$apollo: {
query: sendMock,
mutate: sendMock,
},
}

View File

@ -51,7 +51,7 @@ import GddTransactionListFooter from './AccountOverview/GddTransactionListFooter
import TransactionForm from './AccountOverview/GddSend/TransactionForm.vue'
import TransactionConfirmation from './AccountOverview/GddSend/TransactionConfirmation.vue'
import TransactionResult from './AccountOverview/GddSend/TransactionResult.vue'
import { sendCoins } from '../../graphql/queries.js'
import { sendCoins } from '../../graphql/mutations.js'
const EMPTY_TRANSACTION_DATA = {
email: '',
@ -105,8 +105,8 @@ export default {
async sendTransaction() {
this.loading = true
this.$apollo
.query({
query: sendCoins,
.mutate({
mutation: sendCoins,
variables: this.transactionData,
})
.then(() => {

View File

@ -5,7 +5,7 @@ import Register from './Register'
const localVue = global.localVue
const resgisterUserQueryMock = jest.fn()
const registerUserMutationMock = jest.fn()
const routerPushMock = jest.fn()
describe('Register', () => {
@ -20,10 +20,11 @@ describe('Register', () => {
push: routerPushMock,
},
$apollo: {
query: resgisterUserQueryMock,
mutate: registerUserMutationMock,
},
$store: {
state: {
email: 'peter@lustig.de',
language: null,
},
},
@ -192,7 +193,7 @@ describe('Register', () => {
describe('server sends back error', () => {
beforeEach(async () => {
resgisterUserQueryMock.mockRejectedValue({ message: 'Ouch!' })
registerUserMutationMock.mockRejectedValue({ message: 'Ouch!' })
await wrapper.find('form').trigger('submit')
await flushPromises()
})
@ -217,7 +218,7 @@ describe('Register', () => {
describe('server sends back success', () => {
beforeEach(() => {
resgisterUserQueryMock.mockResolvedValue({
registerUserMutationMock.mockResolvedValue({
data: {
create: 'success',
},
@ -227,7 +228,7 @@ describe('Register', () => {
it('routes to "/thx/register"', async () => {
await wrapper.find('form').trigger('submit')
await flushPromises()
expect(resgisterUserQueryMock).toBeCalledWith(
expect(registerUserMutationMock).toBeCalledWith(
expect.objectContaining({
variables: {
email: 'max.mustermann@gradido.net',

View File

@ -141,7 +141,7 @@
import InputEmail from '../../components/Inputs/InputEmail.vue'
import InputPasswordConfirmation from '../../components/Inputs/InputPasswordConfirmation.vue'
import LanguageSwitchSelect from '../../components/LanguageSwitchSelect.vue'
import { resgisterUserQuery } from '../../graphql/queries'
import { registerUser } from '../../graphql/mutations'
export default {
components: { InputPasswordConfirmation, InputEmail, LanguageSwitchSelect },
@ -190,8 +190,8 @@ export default {
},
async onSubmit() {
this.$apollo
.query({
query: resgisterUserQuery,
.mutate({
mutation: registerUser,
variables: {
email: this.form.email,
firstName: this.form.firstname,

View File

@ -7,6 +7,7 @@ import flushPromises from 'flush-promises'
const localVue = global.localVue
const apolloQueryMock = jest.fn().mockRejectedValue({ message: 'error' })
const apolloMutationMock = jest.fn()
const toasterMock = jest.fn()
const routerPushMock = jest.fn()
@ -36,6 +37,7 @@ describe('ResetPassword', () => {
}),
},
$apollo: {
mutate: apolloMutationMock,
query: apolloQueryMock,
},
}
@ -146,7 +148,7 @@ describe('ResetPassword', () => {
describe('server response with error', () => {
beforeEach(() => {
apolloQueryMock.mockRejectedValue({ message: 'error' })
apolloMutationMock.mockRejectedValue({ message: 'error' })
})
it('toasts an error message', () => {
expect(toasterMock).toHaveBeenCalledWith('error')
@ -155,14 +157,14 @@ describe('ResetPassword', () => {
describe('server response with success', () => {
beforeEach(() => {
apolloQueryMock.mockResolvedValue({
apolloMutationMock.mockResolvedValue({
data: {
resetPassword: 'success',
},
})
})
it('calls the API', () => {
expect(apolloQueryMock).toBeCalledWith(
expect(apolloMutationMock).toBeCalledWith(
expect.objectContaining({
variables: {
sessionId: 1,

View File

@ -48,7 +48,8 @@
</template>
<script>
import InputPasswordConfirmation from '../../components/Inputs/InputPasswordConfirmation'
import { resetPassword, loginViaEmailVerificationCode } from '../../graphql/queries'
import { loginViaEmailVerificationCode } from '../../graphql/queries'
import { resetPassword } from '../../graphql/mutations'
export default {
name: 'ResetPassword',
@ -71,8 +72,8 @@ export default {
methods: {
async onSubmit() {
this.$apollo
.query({
query: resetPassword,
.mutate({
mutation: resetPassword,
variables: {
sessionId: this.sessionId,
email: this.email,

View File

@ -29,7 +29,7 @@ describe('UserCard_FormUserData', () => {
error: toastErrorMock,
},
$apollo: {
query: mockAPIcall,
mutate: mockAPIcall,
},
}

View File

@ -72,7 +72,7 @@
</b-card>
</template>
<script>
import { updateUserInfos } from '../../../graphql/queries'
import { updateUserInfos } from '../../../graphql/mutations'
export default {
name: 'FormUserData',
@ -108,8 +108,8 @@ export default {
async onSubmit(event) {
event.preventDefault()
this.$apollo
.query({
query: updateUserInfos,
.mutate({
mutation: updateUserInfos,
variables: {
email: this.$store.state.email,
firstName: this.form.firstName,

View File

@ -21,7 +21,7 @@ describe('UserCard_FormUserMail', () => {
},
},
$apollo: {
query: mockAPIcall,
mutate: mockAPIcall,
},
}

View File

@ -32,7 +32,7 @@
</b-card>
</template>
<script>
import { updateUserInfos } from '../../../graphql/queries'
import { updateUserInfos } from '../../../graphql/mutations'
export default {
name: 'FormUserMail',
@ -45,8 +45,8 @@ export default {
methods: {
async onSubmit() {
this.$apollo
.query({
query: updateUserInfos,
.mutate({
mutation: updateUserInfos,
variables: {
email: this.$store.state.email,
newEmail: this.newEmail,

View File

@ -25,7 +25,7 @@ describe('UserCard_FormUserPasswort', () => {
error: toastErrorMock,
},
$apollo: {
query: changePasswordProfileMock,
mutate: changePasswordProfileMock,
},
}

View File

@ -42,7 +42,7 @@
<script>
import InputPassword from '../../../components/Inputs/InputPassword'
import InputPasswordConfirmation from '../../../components/Inputs/InputPasswordConfirmation'
import { updateUserInfos } from '../../../graphql/queries'
import { updateUserInfos } from '../../../graphql/mutations'
export default {
name: 'FormUserPasswort',
@ -73,8 +73,8 @@ export default {
},
async onSubmit() {
this.$apollo
.query({
query: updateUserInfos,
.mutate({
mutation: updateUserInfos,
variables: {
email: this.$store.state.email,
password: this.form.password,

View File

@ -35,7 +35,7 @@ describe('UserCard_FormUsername', () => {
error: toastErrorMock,
},
$apollo: {
query: mockAPIcall,
mutate: mockAPIcall,
},
}

View File

@ -67,7 +67,7 @@
</b-card>
</template>
<script>
import { updateUserInfos } from '../../../graphql/queries'
import { updateUserInfos } from '../../../graphql/mutations'
export default {
name: 'FormUsername',
@ -87,8 +87,8 @@ export default {
},
async onSubmit() {
this.$apollo
.query({
query: updateUserInfos,
.mutate({
mutation: updateUserInfos,
variables: {
email: this.$store.state.email,
username: this.form.username,

View File

@ -25,7 +25,7 @@ describe('UserCard_Language', () => {
error: toastErrorMock,
},
$apollo: {
query: mockAPIcall,
mutate: mockAPIcall,
},
}

View File

@ -46,7 +46,6 @@
<div class="text-right" ref="submitButton">
<b-button
:variant="loading ? 'default' : 'success'"
@click="onSubmit"
type="submit"
class="mt-4"
:disabled="loading"
@ -64,7 +63,7 @@
<script>
import { localeChanged } from 'vee-validate'
import LanguageSwitchSelect from '../../../components/LanguageSwitchSelect.vue'
import { updateUserInfos } from '../../../graphql/queries'
import { updateUserInfos } from '../../../graphql/mutations'
export default {
name: 'FormUserLanguage',
@ -88,24 +87,24 @@ export default {
cancelEdit() {
this.showLanguage = true
},
async onSubmit() {
this.$apollo
.query({
query: updateUserInfos,
.mutate({
mutation: updateUserInfos,
variables: {
email: this.$store.state.email,
locale: this.language,
},
})
.then(() => {
this.$store.commit('language', this.language)
this.$i18n.locale = this.language
this.$store.commit('language', this.$i18n.locale)
localeChanged(this.$i18n.locale)
localeChanged(this.language)
this.cancelEdit()
this.$toasted.success(this.$t('languages.success'))
})
.catch((error) => {
this.language = this.$store.state.language
this.$toasted.error(error.message)
})
},