Refactor 'groupMembersQuery' to a function that returns GQL

- Toast some Apollo GQL error messages
This commit is contained in:
Wolfgang Huß 2022-09-18 17:51:26 +02:00
parent a85085ca74
commit 6f6dc4e7fd
5 changed files with 44 additions and 33 deletions

View File

@ -189,13 +189,15 @@ export const groupQuery = () => {
` `
} }
export const groupMembersQuery = gql` export const groupMembersQuery = () => {
query ($id: ID!) { return gql`
GroupMembers(id: $id) { query ($id: ID!) {
id GroupMembers(id: $id) {
name id
slug name
myRoleInGroup slug
myRoleInGroup
}
} }
} `
` }

View File

@ -1049,7 +1049,7 @@ describe('in mode', () => {
variables = { variables = {
id: 'not-existing-group', id: 'not-existing-group',
} }
const { errors } = await query({ query: groupMembersQuery, variables }) const { errors } = await query({ query: groupMembersQuery(), variables })
expect(errors[0]).toHaveProperty('message', 'Not Authorized!') expect(errors[0]).toHaveProperty('message', 'Not Authorized!')
}) })
}) })
@ -1222,7 +1222,7 @@ describe('in mode', () => {
it('finds all members', async () => { it('finds all members', async () => {
const result = await query({ const result = await query({
query: groupMembersQuery, query: groupMembersQuery(),
variables, variables,
}) })
expect(result).toMatchObject({ expect(result).toMatchObject({
@ -1255,7 +1255,7 @@ describe('in mode', () => {
it('finds all members', async () => { it('finds all members', async () => {
const result = await query({ const result = await query({
query: groupMembersQuery, query: groupMembersQuery(),
variables, variables,
}) })
expect(result).toMatchObject({ expect(result).toMatchObject({
@ -1288,7 +1288,7 @@ describe('in mode', () => {
it('finds all members', async () => { it('finds all members', async () => {
const result = await query({ const result = await query({
query: groupMembersQuery, query: groupMembersQuery(),
variables, variables,
}) })
expect(result).toMatchObject({ expect(result).toMatchObject({
@ -1331,7 +1331,7 @@ describe('in mode', () => {
it('finds all members', async () => { it('finds all members', async () => {
const result = await query({ const result = await query({
query: groupMembersQuery, query: groupMembersQuery(),
variables, variables,
}) })
expect(result).toMatchObject({ expect(result).toMatchObject({
@ -1364,7 +1364,7 @@ describe('in mode', () => {
it('finds all members', async () => { it('finds all members', async () => {
const result = await query({ const result = await query({
query: groupMembersQuery, query: groupMembersQuery(),
variables, variables,
}) })
expect(result).toMatchObject({ expect(result).toMatchObject({
@ -1396,7 +1396,7 @@ describe('in mode', () => {
}) })
it('throws authorization error', async () => { it('throws authorization error', async () => {
const { errors } = await query({ query: groupMembersQuery, variables }) const { errors } = await query({ query: groupMembersQuery(), variables })
expect(errors[0]).toHaveProperty('message', 'Not Authorized!') expect(errors[0]).toHaveProperty('message', 'Not Authorized!')
}) })
}) })
@ -1407,7 +1407,7 @@ describe('in mode', () => {
}) })
it('throws authorization error', async () => { it('throws authorization error', async () => {
const { errors } = await query({ query: groupMembersQuery, variables }) const { errors } = await query({ query: groupMembersQuery(), variables })
expect(errors[0]).toHaveProperty('message', 'Not Authorized!') expect(errors[0]).toHaveProperty('message', 'Not Authorized!')
}) })
}) })
@ -1429,7 +1429,7 @@ describe('in mode', () => {
it('finds all members', async () => { it('finds all members', async () => {
const result = await query({ const result = await query({
query: groupMembersQuery, query: groupMembersQuery(),
variables, variables,
}) })
expect(result).toMatchObject({ expect(result).toMatchObject({
@ -1466,7 +1466,7 @@ describe('in mode', () => {
it('finds all members', async () => { it('finds all members', async () => {
const result = await query({ const result = await query({
query: groupMembersQuery, query: groupMembersQuery(),
variables, variables,
}) })
expect(result).toMatchObject({ expect(result).toMatchObject({
@ -1503,7 +1503,7 @@ describe('in mode', () => {
it('finds all members', async () => { it('finds all members', async () => {
const result = await query({ const result = await query({
query: groupMembersQuery, query: groupMembersQuery(),
variables, variables,
}) })
expect(result).toMatchObject({ expect(result).toMatchObject({
@ -1539,7 +1539,7 @@ describe('in mode', () => {
}) })
it('throws authorization error', async () => { it('throws authorization error', async () => {
const { errors } = await query({ query: groupMembersQuery, variables }) const { errors } = await query({ query: groupMembersQuery(), variables })
expect(errors[0]).toHaveProperty('message', 'Not Authorized!') expect(errors[0]).toHaveProperty('message', 'Not Authorized!')
}) })
}) })
@ -1550,7 +1550,7 @@ describe('in mode', () => {
}) })
it('throws authorization error', async () => { it('throws authorization error', async () => {
const { errors } = await query({ query: groupMembersQuery, variables }) const { errors } = await query({ query: groupMembersQuery(), variables })
expect(errors[0]).toHaveProperty('message', 'Not Authorized!') expect(errors[0]).toHaveProperty('message', 'Not Authorized!')
}) })
}) })
@ -2428,7 +2428,7 @@ describe('in mode', () => {
describe('here "closed-group" for example', () => { describe('here "closed-group" for example', () => {
const memberInGroup = async (userId, groupId) => { const memberInGroup = async (userId, groupId) => {
const result = await query({ const result = await query({
query: groupMembersQuery, query: groupMembersQuery(),
variables: { variables: {
id: groupId, id: groupId,
}, },

View File

@ -178,13 +178,15 @@ export const groupQuery = (i18n) => {
` `
} }
export const groupMembersQuery = gql` export const groupMembersQuery = () => {
query ($id: ID!) { return gql`
GroupMembers(id: $id) { query ($id: ID!) {
id GroupMembers(id: $id) {
name id
slug name
myRoleInGroup slug
myRoleInGroup
}
} }
} `
` }

View File

@ -580,17 +580,23 @@ export default {
// followingCount: this.followingCount, // followingCount: this.followingCount,
} }
}, },
error(error) {
this.$toast.error(error.message)
},
fetchPolicy: 'cache-and-network', fetchPolicy: 'cache-and-network',
}, },
GroupMembers: { GroupMembers: {
query() { query() {
return groupMembersQuery return groupMembersQuery()
}, },
variables() { variables() {
return { return {
id: this.$route.params.id, id: this.$route.params.id,
} }
}, },
error(error) {
this.$toast.error(error.message)
},
fetchPolicy: 'cache-and-network', fetchPolicy: 'cache-and-network',
}, },
}, },

View File

@ -32,6 +32,7 @@ export default {
this.responseGroupListQuery = response.data.Group this.responseGroupListQuery = response.data.Group
} catch (error) { } catch (error) {
this.responseGroupListQuery = [] this.responseGroupListQuery = []
this.$toast.error(error.message)
} finally { } finally {
this.pending = false this.pending = false
} }