add new globalSearch resolver + update useSearchRecords hook (#10457)

# Context

To enable search records sorting by ts_rank_cd / ts_rank, we have
decided to add a new search resolver serving `GlobalSearchRecordDTO`.

-----

- [x] Test to add - work in progress


closes https://github.com/twentyhq/core-team-issues/issues/357
This commit is contained in:
Etienne
2025-02-25 17:43:35 +01:00
committed by GitHub
parent 3f25d13999
commit 90a390ee33
27 changed files with 1126 additions and 256 deletions

View File

@ -629,6 +629,16 @@ export type GetServerlessFunctionSourceCodeInput = {
version?: Scalars['String'];
};
export type GlobalSearchRecord = {
__typename?: 'GlobalSearchRecord';
imageUrl?: Maybe<Scalars['String']>;
label: Scalars['String'];
objectSingularName: Scalars['String'];
recordId: Scalars['String'];
tsRank: Scalars['Float'];
tsRankCD: Scalars['Float'];
};
export enum HealthIndicatorId {
connectedAccount = 'connectedAccount',
database = 'database',
@ -1301,6 +1311,7 @@ export type Query = {
getTimelineCalendarEventsFromPersonId: TimelineCalendarEventsWithTotal;
getTimelineThreadsFromCompanyId: TimelineThreadsWithTotal;
getTimelineThreadsFromPersonId: TimelineThreadsWithTotal;
globalSearch: Array<GlobalSearchRecord>;
index: Index;
indexMetadatas: IndexConnection;
object: Object;
@ -1389,6 +1400,13 @@ export type QueryGetTimelineThreadsFromPersonIdArgs = {
};
export type QueryGlobalSearchArgs = {
excludedObjectNameSingulars?: InputMaybe<Array<Scalars['String']>>;
limit: Scalars['Int'];
searchInput: Scalars['String'];
};
export type QueryValidatePasswordResetTokenArgs = {
passwordResetToken: Scalars['String'];
};
@ -2319,6 +2337,15 @@ export type GetClientConfigQueryVariables = Exact<{ [key: string]: never; }>;
export type GetClientConfigQuery = { __typename?: 'Query', clientConfig: { __typename?: 'ClientConfig', signInPrefilled: boolean, isMultiWorkspaceEnabled: boolean, isEmailVerificationRequired: boolean, defaultSubdomain?: string | null, frontDomain: string, debugMode: boolean, analyticsEnabled: boolean, isAttachmentPreviewEnabled: boolean, chromeExtensionId?: string | null, canManageFeatureFlags: boolean, isMicrosoftMessagingEnabled: boolean, isMicrosoftCalendarEnabled: boolean, isGoogleMessagingEnabled: boolean, isGoogleCalendarEnabled: boolean, billing: { __typename?: 'Billing', isBillingEnabled: boolean, billingUrl?: string | null, trialPeriods: Array<{ __typename?: 'BillingTrialPeriodDTO', duration: number, isCreditCardRequired: boolean }> }, authProviders: { __typename?: 'AuthProviders', google: boolean, password: boolean, microsoft: boolean, sso: Array<{ __typename?: 'SSOIdentityProvider', id: string, name: string, type: IdentityProviderType, status: SsoIdentityProviderStatus, issuer: string }> }, support: { __typename?: 'Support', supportDriver: string, supportFrontChatId?: string | null }, sentry: { __typename?: 'Sentry', dsn?: string | null, environment?: string | null, release?: string | null }, captcha: { __typename?: 'Captcha', provider?: CaptchaDriverType | null, siteKey?: string | null }, api: { __typename?: 'ApiConfig', mutationMaximumAffectedRecords: number }, publicFeatureFlags: Array<{ __typename?: 'PublicFeatureFlag', key: FeatureFlagKey, metadata: { __typename?: 'PublicFeatureFlagMetadata', label: string, description: string, imagePath: string } }> } };
export type GlobalSearchQueryVariables = Exact<{
searchInput: Scalars['String'];
limit: Scalars['Int'];
excludedObjectNameSingulars: Array<Scalars['String']> | Scalars['String'];
}>;
export type GlobalSearchQuery = { __typename?: 'Query', globalSearch: Array<{ __typename?: 'GlobalSearchRecord', recordId: string, objectSingularName: string, label: string, imageUrl?: string | null, tsRankCD: number, tsRank: number }> };
export type SkipSyncEmailOnboardingStepMutationVariables = Exact<{ [key: string]: never; }>;
@ -3934,6 +3961,52 @@ export function useGetClientConfigLazyQuery(baseOptions?: Apollo.LazyQueryHookOp
export type GetClientConfigQueryHookResult = ReturnType<typeof useGetClientConfigQuery>;
export type GetClientConfigLazyQueryHookResult = ReturnType<typeof useGetClientConfigLazyQuery>;
export type GetClientConfigQueryResult = Apollo.QueryResult<GetClientConfigQuery, GetClientConfigQueryVariables>;
export const GlobalSearchDocument = gql`
query GlobalSearch($searchInput: String!, $limit: Int!, $excludedObjectNameSingulars: [String!]!) {
globalSearch(
searchInput: $searchInput
limit: $limit
excludedObjectNameSingulars: $excludedObjectNameSingulars
) {
recordId
objectSingularName
label
imageUrl
tsRankCD
tsRank
}
}
`;
/**
* __useGlobalSearchQuery__
*
* To run a query within a React component, call `useGlobalSearchQuery` and pass it any options that fit your needs.
* When your component renders, `useGlobalSearchQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useGlobalSearchQuery({
* variables: {
* searchInput: // value for 'searchInput'
* limit: // value for 'limit'
* excludedObjectNameSingulars: // value for 'excludedObjectNameSingulars'
* },
* });
*/
export function useGlobalSearchQuery(baseOptions: Apollo.QueryHookOptions<GlobalSearchQuery, GlobalSearchQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<GlobalSearchQuery, GlobalSearchQueryVariables>(GlobalSearchDocument, options);
}
export function useGlobalSearchLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GlobalSearchQuery, GlobalSearchQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<GlobalSearchQuery, GlobalSearchQueryVariables>(GlobalSearchDocument, options);
}
export type GlobalSearchQueryHookResult = ReturnType<typeof useGlobalSearchQuery>;
export type GlobalSearchLazyQueryHookResult = ReturnType<typeof useGlobalSearchLazyQuery>;
export type GlobalSearchQueryResult = Apollo.QueryResult<GlobalSearchQuery, GlobalSearchQueryVariables>;
export const SkipSyncEmailOnboardingStepDocument = gql`
mutation SkipSyncEmailOnboardingStep {
skipSyncEmailOnboardingStep {