Add settings menu
This commit is contained in:
37
packages/web/lib/networking/mutations/updateUserMutation.ts
Normal file
37
packages/web/lib/networking/mutations/updateUserMutation.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { gql } from 'graphql-request'
|
||||
import { gqlFetcher } from '../networkHelpers'
|
||||
import { State } from '../fragments/articleFragment'
|
||||
|
||||
export type UpdateUserInput = {
|
||||
name: string
|
||||
bio: string
|
||||
}
|
||||
|
||||
export async function updateUserMutation(
|
||||
input: UpdateUserInput
|
||||
): Promise<string | undefined> {
|
||||
const mutation = gql`
|
||||
mutation UpdateUser($input: UpdateUserInput!) {
|
||||
updateUser(input: $input) {
|
||||
... on UpdateUserSuccess {
|
||||
user {
|
||||
name
|
||||
}
|
||||
}
|
||||
... on UpdateUserError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
try {
|
||||
const data = await gqlFetcher(mutation, {
|
||||
input,
|
||||
})
|
||||
const output = data as any
|
||||
return output.updateUser.user.name
|
||||
} catch (err) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
import { gql } from 'graphql-request'
|
||||
import { gqlFetcher } from '../networkHelpers'
|
||||
import { State } from '../fragments/articleFragment'
|
||||
|
||||
export type UpdateUserProfileInput = {
|
||||
userId: string
|
||||
username: string
|
||||
}
|
||||
|
||||
export async function updateUserProfileMutation(
|
||||
input: UpdateUserProfileInput
|
||||
): Promise<string | undefined> {
|
||||
const mutation = gql`
|
||||
mutation UpdateUserProfile($input: UpdateUserProfileInput!) {
|
||||
updateUserProfile(input: $input) {
|
||||
... on UpdateUserProfileSuccess {
|
||||
user {
|
||||
profile {
|
||||
username
|
||||
}
|
||||
}
|
||||
}
|
||||
... on UpdateUserProfileError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
try {
|
||||
const data = await gqlFetcher(mutation, {
|
||||
input,
|
||||
})
|
||||
const output = data as any
|
||||
console.log('output: ', output)
|
||||
return output.updateUserProfile.user.profile.username
|
||||
} catch (err) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user