Skip to content

Commit 3ed02fe

Browse files
authored
feat: Use typed queries (#1386)
1 parent d6939fe commit 3ed02fe

35 files changed

+1347
-643
lines changed

www/src/_deprecated/components/integrations/OAuthIntegrations.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { useQuery } from '@apollo/client'
21
import { Box, Text } from 'grommet'
32
import { Check as Checkmark } from 'forge-core'
43

54
import { ZOOM_ICON, ZOOM_INSTALL_URL } from './constants'
6-
import { OAUTH_Q } from './queries'
75
import { OAuthService } from './types'
6+
import { useOauthIntegrationsQuery } from '../../../generated/graphql'
87

98
function redirectUrl(format, service) {
109
const location = `${
@@ -66,7 +65,9 @@ function Integration({
6665
}
6766

6867
export function OAuthIntegrations() {
69-
const { data } = useQuery(OAUTH_Q, { fetchPolicy: 'cache-and-network' })
68+
const { data } = useOauthIntegrationsQuery({
69+
fetchPolicy: 'cache-and-network',
70+
})
7071

7172
if (!data) return null
7273

www/src/_deprecated/components/integrations/OauthCreator.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { useEffect, useMemo } from 'react'
22
import { Errors } from 'forge-core'
33
import { useLocation, useNavigate, useParams } from 'react-router-dom'
4-
import { useMutation } from '@apollo/client'
54

65
import { Box, Text } from 'grommet'
76

87
import { LoopingLogo } from '../../../components/utils/AnimatedLogo'
98

10-
import { CREATE_OAUTH } from './queries'
119
import { ParamToService } from './types'
10+
import { useCreateOauthIntegrationMutation } from '../../../generated/graphql'
1211

1312
function OauthError({ error, service }: any) {
1413
return (
@@ -40,11 +39,12 @@ export function OauthCreator() {
4039
redirectUri: `${window.location.origin}${window.location.pathname}`,
4140
}
4241
}, [location])
43-
const [mutation, { loading, data, error }] = useMutation(CREATE_OAUTH, {
44-
variables: {
45-
attributes: { code, redirectUri, service: ParamToService[service] },
46-
},
47-
})
42+
const [mutation, { loading, data, error }] =
43+
useCreateOauthIntegrationMutation({
44+
variables: {
45+
attributes: { code, redirectUri, service: ParamToService[service] },
46+
},
47+
})
4848

4949
useEffect(() => {
5050
mutation()

www/src/_deprecated/components/integrations/queries.ts

-18
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,3 @@ export const DELETE_WEBHOOK = gql`
7171
}
7272
${IntegrationWebhookFragment}
7373
`
74-
75-
export const OAUTH_Q = gql`
76-
query {
77-
oauthIntegrations {
78-
...OauthIntegration
79-
}
80-
}
81-
${OauthIntegration}
82-
`
83-
84-
export const CREATE_OAUTH = gql`
85-
mutation Create($attributes: OauthIntegrationAttributes!) {
86-
createOauthIntegration(attributes: $attributes) {
87-
...OauthIntegration
88-
}
89-
}
90-
${OauthIntegration}
91-
`

www/src/components/account/CreateRole.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useCallback, useContext, useMemo, useState } from 'react'
2-
import { useMutation } from '@apollo/client'
32
import { Button } from 'honorable'
43
import { Modal } from '@pluralsh/design-system'
54
import uniqWith from 'lodash/uniqWith'
@@ -9,7 +8,9 @@ import { appendConnection, updateCache } from '../../utils/graphql'
98

109
import SubscriptionContext from '../../contexts/SubscriptionContext'
1110

12-
import { CREATE_ROLE, ROLES_Q } from './queries'
11+
import { useCreateRoleMutation } from '../../generated/graphql'
12+
13+
import { ROLES_Q } from './queries'
1314

1415
import { Actions } from './Actions'
1516
import { sanitize } from './utils'
@@ -42,15 +43,15 @@ export function CreateRole({ q }: any) {
4243
setCreateModalVisible(false)
4344
}, [])
4445

45-
const [mutation, { loading, error }] = useMutation(CREATE_ROLE, {
46+
const [mutation, { loading, error }] = useCreateRoleMutation({
4647
variables: {
4748
attributes: { ...attributes, roleBindings: roleBindings.map(sanitize) },
4849
},
49-
update: (cache, { data: { createRole } }) =>
50+
update: (cache, { data }) =>
5051
updateCache(cache, {
5152
query: ROLES_Q,
5253
variables: { q },
53-
update: (prev) => appendConnection(prev, createRole, 'roles'),
54+
update: (prev) => appendConnection(prev, data?.createRole, 'roles'),
5455
}),
5556
onCompleted: () => resetAndClose(),
5657
})

www/src/components/account/CreateServiceAccount.tsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ import SubscriptionContext from '../../contexts/SubscriptionContext'
2020

2121
import { Confirm } from '../utils/Confirm'
2222

23-
import {
24-
CREATE_SERVICE_ACCOUNT,
25-
UPDATE_SERVICE_ACCOUNT,
26-
USERS_Q,
27-
} from './queries'
23+
import { useCreateServiceAccountMutation } from '../../generated/graphql'
24+
25+
import { UPDATE_SERVICE_ACCOUNT, USERS_Q } from './queries'
2826

2927
import { MoreMenu } from './MoreMenu'
3028

@@ -274,18 +272,19 @@ export function CreateServiceAccount({ q }: any) {
274272
setCreateModalVisible(false)
275273
}, [])
276274

277-
const [mutation, { loading, error }] = useMutation(CREATE_SERVICE_ACCOUNT, {
275+
const [mutation, { loading, error }] = useCreateServiceAccountMutation({
278276
variables: {
279277
attributes: {
280278
...attributes,
281279
impersonationPolicy: { bindings: bindings.map(sanitize) },
282280
},
283281
},
284-
update: (cache, { data: { createServiceAccount } }) =>
282+
update: (cache, { data }) =>
285283
updateCache(cache, {
286284
query: USERS_Q,
287285
variables: { q, serviceAccount: true },
288-
update: (prev) => appendConnection(prev, createServiceAccount, 'users'),
286+
update: (prev) =>
287+
appendConnection(prev, data?.createServiceAccount, 'users'),
289288
}),
290289
onCompleted: () => {
291290
resetAndClose()

www/src/components/account/DnsRecords.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQuery } from '@apollo/client'
1+
import { useQuery } from '@apollo/client'
22
import { Box } from 'grommet'
33
import { Button, Div, Flex, Span } from 'honorable'
44
import moment from 'moment'
@@ -18,19 +18,21 @@ import { Table, TableData, TableRow } from '../utils/Table'
1818
import { ProviderIcon } from '../utils/ProviderIcon'
1919
import { Confirm } from '../utils/Confirm'
2020

21-
import { DELETE_DNS_RECORD, DNS_RECORDS } from './queries'
21+
import { useDeleteDnsRecordMutation } from '../../generated/graphql'
22+
23+
import { DNS_RECORDS } from './queries'
2224

2325
function DeleteRecord({ record, domain }: any) {
2426
const [confirm, setConfirm] = useState(false)
25-
const [mutation, { loading, error }] = useMutation(DELETE_DNS_RECORD, {
27+
const [mutation, { loading, error }] = useDeleteDnsRecordMutation({
2628
variables: { name: record.name, type: record.type },
27-
update: (cache, { data: { deleteDnsRecord } }) =>
29+
update: (cache, { data }) =>
2830
updateCache(cache, {
2931
query: DNS_RECORDS,
3032
variables: { id: domain.id },
3133
update: (prev) =>
3234
deepUpdate(prev, 'dnsDomain', (domain) =>
33-
removeConnection(domain, deleteDnsRecord, 'dnsRecords')
35+
removeConnection(domain, data?.deleteDnsRecord, 'dnsRecords')
3436
),
3537
}),
3638
onCompleted: () => setConfirm(false),

www/src/components/account/Domains.tsx

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQuery } from '@apollo/client'
1+
import { useQuery } from '@apollo/client'
22
import { Box } from 'grommet'
33
import { Flex, Span } from 'honorable'
44
import moment from 'moment'
@@ -25,11 +25,15 @@ import { Table, TableData, TableRow } from '../utils/Table'
2525
import ListInput from '../utils/ListInput'
2626
import { List } from '../utils/List'
2727
import { Confirm } from '../utils/Confirm'
28-
import { DnsRecordFragment } from '../../generated/graphql'
28+
import {
29+
DnsRecordFragment,
30+
useDeleteDomainMutation,
31+
useUpdateDomainMutation,
32+
} from '../../generated/graphql'
2933

3034
import LoadingIndicator from '../utils/LoadingIndicator'
3135

32-
import { DELETE_DOMAIN, DNS_DOMAINS, UPDATE_DOMAIN } from './queries'
36+
import { DNS_DOMAINS } from './queries'
3337
import { Actions } from './Actions'
3438
import { MoreMenu } from './MoreMenu'
3539
import { BindingInput } from './Typeaheads'
@@ -52,12 +56,13 @@ function Header({ q, setQ }: any) {
5256
function DomainOptions({ domain, setDomain }: any) {
5357
const [confirm, setConfirm] = useState(false)
5458
const [edit, setEdit] = useState(false)
55-
const [mutation, { loading, error }] = useMutation(DELETE_DOMAIN, {
59+
const [mutation, { loading, error }] = useDeleteDomainMutation({
5660
variables: { id: domain.id },
57-
update: (cache, { data: { deleteDomain } }) => {
61+
update: (cache, { data }) => {
5862
updateCache(cache, {
5963
query: DNS_DOMAINS,
60-
update: (prev) => removeConnection(prev, deleteDomain, 'dnsDomains'),
64+
update: (prev) =>
65+
removeConnection(prev, data?.deleteDomain, 'dnsDomains'),
6166
variables: {},
6267
})
6368
},
@@ -124,7 +129,7 @@ function AccessPolicy({ domain: { id, accessPolicy }, edit, setEdit }: any) {
124129
accessPolicy ? accessPolicy.bindings : []
125130
)
126131
const uniqueBindings = useMemo(() => uniqWith(bindings, isEqual), [bindings])
127-
const [mutation, { loading, error }] = useMutation(UPDATE_DOMAIN, {
132+
const [mutation, { loading, error }] = useUpdateDomainMutation({
128133
variables: {
129134
id,
130135
attributes: {

www/src/components/account/EditRole.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { useMutation } from '@apollo/client'
21
import { Button } from 'honorable'
32
import { Modal } from '@pluralsh/design-system'
43
import { useMemo, useState } from 'react'
54
import uniqWith from 'lodash/uniqWith'
65
import isEqual from 'lodash/isEqual'
76

8-
import { UPDATE_ROLE } from './queries'
7+
import { useUpdateRoleMutation } from '../../generated/graphql'
98

109
import { Actions } from './Actions'
1110
import { sanitize } from './utils'
@@ -25,7 +24,7 @@ export function EditRole({ role }: any) {
2524
[roleBindings]
2625
)
2726

28-
const [mutation, { loading, error }] = useMutation(UPDATE_ROLE, {
27+
const [mutation, { loading, error }] = useUpdateRoleMutation({
2928
variables: {
3029
id: role.id,
3130
attributes: { ...attributes, roleBindings: roleBindings.map(sanitize) },

www/src/components/account/InviteUser.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useMutation } from '@apollo/client'
21
import {
32
Codeline,
43
MailIcon,
@@ -15,7 +14,8 @@ import { useCurrentUser } from '../../contexts/CurrentUserContext'
1514
import SubscriptionContext from '../../contexts/SubscriptionContext'
1615
import { GqlError } from '../utils/Alert'
1716

18-
import { CREATE_INVITE } from './queries'
17+
import { useCreateInviteMutation } from '../../generated/graphql'
18+
1919
import { inviteLink } from './utils'
2020

2121
const MAX_OPEN_SOURCE_USERS = 5
@@ -27,10 +27,10 @@ export function InviteUser({ refetch }: { refetch?: (() => void) | null }) {
2727
const [invite, setInvite] = useState<any>(null)
2828
const { account } = useCurrentUser()
2929
const { isGrandfathered, isPaidPlan } = useContext(SubscriptionContext)
30-
const [mutation, { loading, error, reset }] = useMutation(CREATE_INVITE, {
30+
const [mutation, { loading, error, reset }] = useCreateInviteMutation({
3131
variables: { attributes: { email } },
3232
onCompleted: (data) => {
33-
setInvite(data && data.createInvite)
33+
setInvite(data?.createInvite)
3434
refetch?.()
3535
},
3636
})

www/src/components/account/Invites.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQuery } from '@apollo/client'
1+
import { useQuery } from '@apollo/client'
22
import moment from 'moment'
33
import { useEffect, useState } from 'react'
44
import { Div, Flex, Text } from 'honorable'
@@ -23,19 +23,22 @@ import LoadingIndicator from '../utils/LoadingIndicator'
2323

2424
import { Confirm } from '../utils/Confirm'
2525

26-
import { DELETE_INVITE, INVITES_Q } from './queries'
26+
import { useDeleteInviteMutation } from '../../generated/graphql'
27+
28+
import { INVITES_Q } from './queries'
2729
import { inviteLink } from './utils'
2830

2931
function DeleteInvite({ invite }: any) {
3032
const [confirm, setConfirm] = useState(false)
31-
const [mutation, { loading, error }] = useMutation(DELETE_INVITE, {
33+
const [mutation, { loading, error }] = useDeleteInviteMutation({
3234
variables: { id: invite.id },
3335
onCompleted: () => setConfirm(false),
34-
update: (cache, { data: { deleteInvite } }) =>
36+
update: (cache, { data }) =>
3537
updateCache(cache, {
3638
query: INVITES_Q,
3739
variables: {},
38-
update: (invites) => removeConnection(invites, deleteInvite, 'invites'),
40+
update: (invites) =>
41+
removeConnection(invites, data?.deleteInvite, 'invites'),
3942
}),
4043
})
4144

www/src/components/account/Roles.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQuery } from '@apollo/client'
1+
import { useQuery } from '@apollo/client'
22
import { Box } from 'grommet'
33
import isEmpty from 'lodash/isEmpty'
44
import { Flex } from 'honorable'
@@ -16,7 +16,7 @@ import {
1616
} from '../../utils/graphql'
1717
import { DeleteIconButton } from '../utils/IconButtons'
1818
import { StandardScroller } from '../utils/SmoothScroller'
19-
import { Permission } from '../../generated/graphql'
19+
import { Permission, useDeleteRoleMutation } from '../../generated/graphql'
2020
import { canEdit } from '../../utils/account'
2121
import LoadingIndicator from '../utils/LoadingIndicator'
2222

@@ -26,7 +26,7 @@ import { Confirm } from '../utils/Confirm'
2626

2727
import BillingTrialBanner from './billing/BillingTrialBanner'
2828

29-
import { DELETE_ROLE, ROLES_Q } from './queries'
29+
import { ROLES_Q } from './queries'
3030
import { hasRbac } from './utils'
3131
import { Info } from './Info'
3232
import { EditRole } from './EditRole'
@@ -51,13 +51,13 @@ function Role({ role, q }: any) {
5151
const [confirm, setConfirm] = useState(false)
5252
const me = useContext(CurrentUserContext)
5353
const editable = canEdit(me, me.account) || hasRbac(me, Permission.Users)
54-
const [mutation, { loading, error }] = useMutation(DELETE_ROLE, {
54+
const [mutation, { loading, error }] = useDeleteRoleMutation({
5555
variables: { id: role.id },
5656
update: (cache, { data }) =>
5757
updateCache(cache, {
5858
query: ROLES_Q,
5959
variables: { q },
60-
update: (prev) => removeConnection(prev, data.deleteRole, 'roles'),
60+
update: (prev) => removeConnection(prev, data?.deleteRole, 'roles'),
6161
}),
6262
onCompleted: () => setConfirm(false),
6363
})

0 commit comments

Comments
 (0)