mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add revoke api key mutation in Web
This commit is contained in:
parent
fba142eb3b
commit
aada005e50
1 changed files with 39 additions and 0 deletions
|
|
@ -0,0 +1,39 @@
|
|||
import { gql } from 'graphql-request'
|
||||
import { gqlFetcher } from '../networkHelpers'
|
||||
import { ApiKey } from '../queries/useGetApiKeysQuery'
|
||||
|
||||
interface RevokeApiKeyResult {
|
||||
revokeApiKey: RevokeApiKey
|
||||
errorCodes?: unknown[]
|
||||
}
|
||||
|
||||
type RevokeApiKey = {
|
||||
apiKey: ApiKey
|
||||
}
|
||||
|
||||
export async function revokeApiKeyMutation(
|
||||
id: string
|
||||
): Promise<any | undefined> {
|
||||
const mutation = gql`
|
||||
mutation {
|
||||
revokeApiKey(id: "${id}") {
|
||||
... on RevokeApiKeySuccess {
|
||||
apiKey {
|
||||
id
|
||||
}
|
||||
}
|
||||
... on RevokeApiKeyError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
try {
|
||||
const data = (await gqlFetcher(mutation)) as RevokeApiKeyResult
|
||||
return data.errorCodes ? undefined : data.revokeApiKey.apiKey.id
|
||||
} catch (error) {
|
||||
console.log('revokeApiKeyMutation error', error)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue