Skip to content

Commit

Permalink
refactor: clean up generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Sep 17, 2023
1 parent cd4f299 commit 892de73
Show file tree
Hide file tree
Showing 22 changed files with 129 additions and 124 deletions.
4 changes: 2 additions & 2 deletions api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ type PagingMeta {
type Query {
adminFindManyEmail(input: AdminFindManyEmailInput!): [Email!]
adminFindManyIdentity(input: AdminFindManyIdentityInput!): [Identity!]
adminFindManyUser(input: AdminFindManyUserInput!): UserPaging
adminFindManyUser(input: AdminFindManyUserInput!): UserPaging!
adminFindOneUser(userId: String!): User
appConfig: AppConfig!
me: User
uptime: Float!
userFindManyIdentity: [Identity!]
userFindManyUser(input: UserFindManyUserInput!): UserPaging
userFindManyUser(input: UserFindManyUserInput!): UserPaging!
userFindOneUser(username: String!): User
userRequestIdentityChallenge(input: RequestIdentityChallengeInput!): IdentityChallenge
}
Expand Down
2 changes: 1 addition & 1 deletion libs/api/user/feature/src/lib/api-user-admin.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ApiUserAdminResolver {
return this.service.admin.deleteUser(userId)
}

@Query(() => UserPaging, { nullable: true })
@Query(() => UserPaging)
adminFindManyUser(@Args('input') input: AdminFindManyUserInput) {
return this.service.admin.findManyUser(input)
}
Expand Down
2 changes: 1 addition & 1 deletion libs/api/user/feature/src/lib/api-user-user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
export class ApiUserUserResolver {
constructor(private readonly service: ApiUserService) {}

@Query(() => UserPaging, { nullable: true })
@Query(() => UserPaging)
userFindManyUser(@Args('input') input: UserFindManyUserInput) {
return this.service.user.findManyUser(input)
}
Expand Down
12 changes: 6 additions & 6 deletions libs/sdk/src/generated/graphql-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ export type Query = {
__typename?: 'Query'
adminFindManyEmail?: Maybe<Array<Email>>
adminFindManyIdentity?: Maybe<Array<Identity>>
adminFindManyUser?: Maybe<UserPaging>
adminFindManyUser: UserPaging
adminFindOneUser?: Maybe<User>
appConfig: AppConfig
me?: Maybe<User>
uptime: Scalars['Float']['output']
userFindManyIdentity?: Maybe<Array<Identity>>
userFindManyUser?: Maybe<UserPaging>
userFindManyUser: UserPaging
userFindOneUser?: Maybe<User>
userRequestIdentityChallenge?: Maybe<IdentityChallenge>
}
Expand Down Expand Up @@ -724,7 +724,7 @@ export type AdminFindManyUserQueryVariables = Exact<{

export type AdminFindManyUserQuery = {
__typename?: 'Query'
paging?: {
paging: {
__typename?: 'UserPaging'
data: Array<{
__typename?: 'User'
Expand All @@ -749,7 +749,7 @@ export type AdminFindManyUserQuery = {
previousPage?: number | null
totalCount?: number | null
}
} | null
}
}

export type AdminFindOneUserQueryVariables = Exact<{
Expand Down Expand Up @@ -801,7 +801,7 @@ export type UserFindManyUserQueryVariables = Exact<{

export type UserFindManyUserQuery = {
__typename?: 'Query'
paging?: {
paging: {
__typename?: 'UserPaging'
data: Array<{
__typename?: 'User'
Expand All @@ -826,7 +826,7 @@ export type UserFindManyUserQuery = {
previousPage?: number | null
totalCount?: number | null
}
} | null
}
}

export type UserFindOneUserQueryVariables = Exact<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class ApiTestAdminResolver {
return this.service.admin.deleteTest(testId);
}
@Query(() => TestPaging, { nullable: true })
@Query(() => TestPaging)
adminFindManyTest(@Args('input') input: AdminFindManyTestInput) {
return this.service.admin.findManyTest(input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class <%= app.className %><%= model.className %><%= admin.className %>Res
return this.service.<%= admin.propertyName %>.delete<%= model.className %>(<%= model.propertyName %>Id)
}

@Query(() => <%= model.className %>Paging, { nullable: true })
@Query(() => <%= model.className %>Paging)
<%= admin.propertyName %>FindMany<%= model.className %>(@Args('input') input: <%= admin.className %>FindMany<%= model.className %>Input) {
return this.service.<%= admin.propertyName %>.findMany<%= model.className %>(input)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,24 @@ export function useAdminFindMany<%= modelClassName %>(props?: Partial<AdminFindM
const [search, setSearch] = useState<string>(props?.search ?? '')

const input: AdminFindMany<%= modelClassName %>Input = { page, limit, search }
const query = useQuery(['admin', 'find-many-<%= modelPropertyName %>', input], () => sdk.adminFindMany<%= modelClassName %>({ input }).then((res) => res.data))
const query = useQuery({
queryKey: ['admin', 'find-many-<%= modelFileName %>', input],
queryFn: () => sdk.adminFindMany<%= modelClassName %>({ input }).then((res) => res.data),
})
const total = query.data?.paging?.meta?.totalCount ?? 0
const items = query.data?.paging.data ?? []

return {
items,
query,
pagination: useUiPagination({
page,
setPage,
limit,
setLimit,
total,
}),
setSearch,
create<%= modelClassName %>: (input: AdminCreate<%= modelClassName %>Input) =>
sdk
.adminCreate<%= modelClassName %>({ input })
Expand All @@ -38,14 +52,5 @@ export function useAdminFindMany<%= modelClassName %>(props?: Partial<AdminFindM
showNotificationSuccess('<%= modelClassName %> deleted')
return query.refetch()
}),
query,
setSearch,
pagination: useUiPagination({
page,
setPage,
limit,
setLimit,
total,
}),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { useQuery } from '@tanstack/react-query'

export function useAdminFindOne<%= modelClassName %>(<%= modelPropertyName %>Id: string) {
const sdk = useWebSdk()
const query = useQuery(
['admin', 'find-one-<%= modelPropertyName %>', <%= modelPropertyName %>Id],
() => sdk.adminFindOne<%= modelClassName %>({ <%= modelPropertyName %>Id }).then((res) => res.data),
{ retry: 0 },
)
const query = useQuery({
queryKey: ['admin', 'find-one-<%= modelFileName %>', <%= modelPropertyName %>Id],
queryFn: () => sdk.adminFindOne<%= modelClassName %>({ <%= modelPropertyName %>Id }).then((res) => res.data),
retry: 0
})
const <%= modelPropertyName %> = query.data?.item ?? undefined

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AdminUi<%= modelClassName %>Table } from '@<%= npmScope %>/<%= app %>/<
import { Link } from 'react-router-dom'

export function WebAdmin<%= modelClassName %>ListFeature() {
const { delete<%= modelClassName %>, pagination, query, setSearch } = useAdminFindMany<%= modelClassName %>()
const { delete<%= modelClassName %>, items, pagination, query, setSearch } = useAdminFindMany<%= modelClassName %>()

return (
<UiAdminPage
Expand All @@ -24,7 +24,7 @@ export function WebAdmin<%= modelClassName %>ListFeature() {

{query.isLoading ? (
<UiLoader />
) : query?.data?.paging?.data?.length ? (
) : items?.length ? (
<AdminUi<%= modelClassName %>Table
delete<%= modelClassName %>={(<%= modelPropertyName %>) => {
if (!window.confirm('Are you sure?')) return
Expand Down
2 changes: 1 addition & 1 deletion libs/web/auth/data-access/src/lib/web-auth.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function useAppConfig() {
const sdk = useWebSdk()

return useQuery({
queryKey: ['appConfig'],
queryKey: ['app-config'],
queryFn: () => sdk.appConfig().then((res) => res.data),
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ export function useAdminIdentities({ ownerId, provider }: { ownerId?: string; pr
provider: provider,
})

const query = useQuery(['admin', 'identities', 'find', input], () =>
sdk.adminFindManyIdentity({ input }).then((res) => res.data),
)
const query = useQuery({
queryKey: ['admin', 'find-many-identity', input],
queryFn: () => sdk.adminFindManyIdentity({ input }).then((res) => res.data),
})

return {
items: query.data?.items ?? [],
query,
createIdentity: async (input: AdminCreateIdentityInput) => {
if (!ownerId) {
showNotificationError('No owner ID')
Expand Down Expand Up @@ -50,7 +53,5 @@ export function useAdminIdentities({ ownerId, provider }: { ownerId?: string; pr
return false
})
},
identities: query.data?.items ?? [],
query,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useMemo } from 'react'
export function useUserIdentities() {
const sdk = useWebSdk()
const query = useQuery({
queryKey: ['user', 'identities'],
queryKey: ['user', 'find-many-identity'],
queryFn: () => sdk.userFindManyIdentity().then((res) => res?.data),
})

Expand All @@ -32,12 +32,12 @@ export function useUserIdentities() {
const discordIdentity = items.find((x) => x.provider === IdentityProvider.Discord)

return {
query,
grouped,
items,
expiredDiscord: discordIdentity?.expired ?? false,
grouped,
hasDiscord: !!discordIdentity,
hasSolana: items.some((x) => x.provider === IdentityProvider.Solana),
items,
query,
deleteIdentity(identityId: string) {
if (!window.confirm('Are you sure?')) {
return
Expand Down
12 changes: 5 additions & 7 deletions libs/web/shell/data-access/src/lib/web-sdk-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Sdk } from '@pubkey-stack/sdk'
import { useQuery } from '@tanstack/react-query'

export function useMeQuery(sdk: Sdk) {
return useQuery(
['me'],
async () => {
return useQuery({
queryKey: ['me'],
queryFn: async () => {
try {
const res = await sdk.me().then((res) => res?.data)
console.log(`useMeQuery: logged in as ${res.me?.username}`)
Expand All @@ -14,8 +14,6 @@ export function useMeQuery(sdk: Sdk) {
return null
}
},
{
retry: 0,
},
)
retry: 0,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export function useAdminFindManyEmail(userId: string) {
ownerId: userId,
})

const query = useQuery(['admin', 'emails', 'find', input], () =>
sdk.adminFindManyEmail({ input }).then((res) => res.data),
)
const query = useQuery({
queryKey: ['admin', 'find-many-email', input],
queryFn: () => sdk.adminFindManyEmail({ input }).then((res) => res.data),
})

return {
emails: query.data?.items ?? [],
Expand Down
37 changes: 20 additions & 17 deletions libs/web/user/data-access/src/lib/use-admin-find-many-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,28 @@ export function useAdminFindManyUser() {
const [search, setSearch] = useState<string>('')

const input: AdminFindManyUserInput = { limit, page, role, search, status }
const query = useQuery(['admin', 'users', 'find', input], () =>
sdk.adminFindManyUser({ input }).then((res) => res.data),
)
const total = query.data?.paging?.meta?.totalCount ?? 0
const query = useQuery({
queryKey: ['admin', 'find-many-user', input],
queryFn: () => sdk.adminFindManyUser({ input }).then((res) => res.data),
})
const total = query.data?.paging.meta?.totalCount ?? 0
const items = query.data?.paging.data ?? []

return {
items,
query,
role,
status,
pagination: useUiPagination({
limit,
page,
total,
setLimit,
setPage,
}),
setRole,
setSearch,
setStatus,
createUser: (input: AdminCreateUserInput) =>
sdk
.adminCreateUser({ input })
Expand All @@ -42,18 +58,5 @@ export function useAdminFindManyUser() {
showNotificationSuccess('User deleted')
return query.refetch()
}),
query,
role,
setRole,
setSearch,
setStatus,
status,
pagination: useUiPagination({
page,
setPage,
limit,
setLimit,
total,
}),
}
}
12 changes: 6 additions & 6 deletions libs/web/user/data-access/src/lib/use-admin-find-one-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { useWebSdk } from '@pubkey-stack/web/shell/data-access'
import { showNotificationError, showNotificationSuccess } from '@pubkey-stack/web/ui/notifications'
import { useQuery } from '@tanstack/react-query'

export function useAdminUser(userId: string) {
export function useAdminFindOneUser({ userId }: { userId: string }) {
const sdk = useWebSdk()
const query = useQuery(
['admin', 'users', 'get', userId],
() => sdk.adminFindOneUser({ userId }).then((res) => res.data),
{ retry: 0 },
)
const query = useQuery({
queryKey: ['admin', 'find-one-user', userId],
queryFn: () => sdk.adminFindOneUser({ userId }).then((res) => res.data),
retry: 0,
})
const user = query.data?.item ?? undefined

return {
Expand Down
16 changes: 7 additions & 9 deletions libs/web/user/data-access/src/lib/use-user-find-many-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import { useQuery } from '@tanstack/react-query'

export function useUserFindManyUser(input: UserFindManyUserInput) {
const sdk = useWebSdk()
const query = useQuery(
['user', 'users', 'get', input],
() => sdk.userFindManyUser({ input }).then((res) => res.data),
{
retry: 0,
},
)
const query = useQuery({
queryKey: ['user', 'find-many-user', input],
queryFn: () => sdk.userFindManyUser({ input }).then((res) => res.data),
retry: 0,
})

return {
data: query.data?.paging?.data ?? [],
meta: query.data?.paging?.meta,
data: query.data?.paging.data ?? [],
meta: query.data?.paging.meta,
query,
}
}
12 changes: 5 additions & 7 deletions libs/web/user/data-access/src/lib/use-user-fine-one-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { useQuery } from '@tanstack/react-query'

export function useUserFineOneUser(username: string) {
const sdk = useWebSdk()
const query = useQuery(
['user', 'users', 'get', username],
() => sdk.userFindOneUser({ username }).then((res) => res.data),
{
retry: 0,
},
)
const query = useQuery({
queryKey: ['user', 'find-one-user', username],
queryFn: () => sdk.userFindOneUser({ username }).then((res) => res.data),
retry: 0,
})

return {
user: query.data?.item,
Expand Down
Loading

0 comments on commit 892de73

Please sign in to comment.