Add JSON field type and Event object (#4566)

* Add JSON field type and Event object

* Simplify code

* Adress PR comments and add featureFlag
This commit is contained in:
Félix Malfait
2024-03-19 21:54:08 +01:00
committed by GitHub
parent 4ab426c52a
commit 4bfb90657f
51 changed files with 575 additions and 117 deletions

View File

@ -66,10 +66,32 @@ export type AuthTokens = {
export type Billing = {
__typename?: 'Billing';
billingFreeTrialDurationInDays?: Maybe<Scalars['Float']['output']>;
billingUrl: Scalars['String']['output'];
billingUrl?: Maybe<Scalars['String']['output']>;
isBillingEnabled: Scalars['Boolean']['output'];
};
export type BillingSubscription = {
__typename?: 'BillingSubscription';
id: Scalars['ID']['output'];
status: Scalars['String']['output'];
};
export type BillingSubscriptionFilter = {
and?: InputMaybe<Array<BillingSubscriptionFilter>>;
id?: InputMaybe<IdFilterComparison>;
or?: InputMaybe<Array<BillingSubscriptionFilter>>;
};
export type BillingSubscriptionSort = {
direction: SortDirection;
field: BillingSubscriptionSortFields;
nulls?: InputMaybe<SortNulls>;
};
export enum BillingSubscriptionSortFields {
Id = 'id'
}
export type BooleanFieldComparison = {
is?: InputMaybe<Scalars['Boolean']['input']>;
isNot?: InputMaybe<Scalars['Boolean']['input']>;
@ -241,6 +263,7 @@ export enum FieldMetadataType {
DateTime = 'DATE_TIME',
Email = 'EMAIL',
FullName = 'FULL_NAME',
Json = 'JSON',
Link = 'LINK',
MultiSelect = 'MULTI_SELECT',
Number = 'NUMBER',
@ -301,7 +324,6 @@ export type Mutation = {
activateWorkspace: Workspace;
challenge: LoginToken;
checkoutSession: SessionEntity;
createEvent: Analytics;
createOneField: Field;
createOneObject: Object;
createOneRefreshToken: RefreshToken;
@ -318,6 +340,7 @@ export type Mutation = {
impersonate: Verify;
renewToken: AuthTokens;
signUp: LoginToken;
track: Analytics;
updateOneField: Field;
updateOneObject: Object;
updatePasswordViaResetToken: InvalidatePassword;
@ -347,12 +370,6 @@ export type MutationCheckoutSessionArgs = {
};
export type MutationCreateEventArgs = {
data: Scalars['JSON']['input'];
type: Scalars['String']['input'];
};
export type MutationCreateOneFieldArgs = {
input: CreateOneFieldMetadataInput;
};
@ -421,6 +438,12 @@ export type MutationSignUpArgs = {
};
export type MutationTrackArgs = {
data: Scalars['JSON']['input'];
type: Scalars['String']['input'];
};
export type MutationUpdateOneFieldArgs = {
input: UpdateOneFieldMetadataInput;
};
@ -631,6 +654,23 @@ export type RelationConnection = {
pageInfo: PageInfo;
};
export type RelationDefinition = {
__typename?: 'RelationDefinition';
direction: RelationDefinitionType;
sourceFieldMetadata: Field;
sourceObjectMetadata: Object;
targetFieldMetadata: Field;
targetObjectMetadata: Object;
};
/** Relation definition type */
export enum RelationDefinitionType {
ManyToMany = 'MANY_TO_MANY',
ManyToOne = 'MANY_TO_ONE',
OneToMany = 'ONE_TO_MANY',
OneToOne = 'ONE_TO_ONE'
}
export type RelationDeleteResponse = {
__typename?: 'RelationDeleteResponse';
createdAt?: Maybe<Scalars['DateTime']['output']>;
@ -831,7 +871,9 @@ export type Workspace = {
__typename?: 'Workspace';
activationStatus: Scalars['String']['output'];
allowImpersonation: Scalars['Boolean']['output'];
billingSubscriptions?: Maybe<Array<BillingSubscription>>;
createdAt: Scalars['DateTime']['output'];
currentBillingSubscription?: Maybe<BillingSubscription>;
deletedAt?: Maybe<Scalars['DateTime']['output']>;
displayName?: Maybe<Scalars['String']['output']>;
domainName?: Maybe<Scalars['String']['output']>;
@ -844,6 +886,12 @@ export type Workspace = {
};
export type WorkspaceBillingSubscriptionsArgs = {
filter?: BillingSubscriptionFilter;
sorting?: Array<BillingSubscriptionSort>;
};
export type WorkspaceFeatureFlagsArgs = {
filter?: FeatureFlagFilter;
sorting?: Array<FeatureFlagSort>;
@ -886,6 +934,7 @@ export type Field = {
label: Scalars['String']['output'];
name: Scalars['String']['output'];
options?: Maybe<Scalars['JSON']['output']>;
relationDefinition?: Maybe<RelationDefinition>;
toRelationMetadata?: Maybe<Relation>;
type: FieldMetadataType;
updatedAt: Scalars['DateTime']['output'];

View File

@ -183,6 +183,7 @@ export enum FieldMetadataType {
DateTime = 'DATE_TIME',
Email = 'EMAIL',
FullName = 'FULL_NAME',
Json = 'JSON',
Link = 'LINK',
MultiSelect = 'MULTI_SELECT',
Number = 'NUMBER',
@ -243,7 +244,6 @@ export type Mutation = {
activateWorkspace: Workspace;
challenge: LoginToken;
checkoutSession: SessionEntity;
createEvent: Analytics;
createOneObject: Object;
createOneRefreshToken: RefreshToken;
deleteCurrentWorkspace: Workspace;
@ -256,6 +256,7 @@ export type Mutation = {
impersonate: Verify;
renewToken: AuthTokens;
signUp: LoginToken;
track: Analytics;
updateOneObject: Object;
updatePasswordViaResetToken: InvalidatePassword;
updateWorkspace: Workspace;
@ -284,12 +285,6 @@ export type MutationCheckoutSessionArgs = {
};
export type MutationCreateEventArgs = {
data: Scalars['JSON'];
type: Scalars['String'];
};
export type MutationDeleteOneObjectArgs = {
input: DeleteOneObjectInput;
};
@ -328,6 +323,12 @@ export type MutationSignUpArgs = {
};
export type MutationTrackArgs = {
data: Scalars['JSON'];
type: Scalars['String'];
};
export type MutationUpdatePasswordViaResetTokenArgs = {
newPassword: Scalars['String'];
passwordResetToken: Scalars['String'];
@ -917,13 +918,13 @@ export type GetTimelineThreadsFromPersonIdQuery = { __typename?: 'Query', getTim
export type TimelineThreadFragment = { __typename?: 'TimelineThread', id: string, subject: string, lastMessageReceivedAt: string };
export type CreateEventMutationVariables = Exact<{
export type TrackMutationVariables = Exact<{
type: Scalars['String'];
data: Scalars['JSON'];
}>;
export type CreateEventMutation = { __typename?: 'Mutation', createEvent: { __typename?: 'Analytics', success: boolean } };
export type TrackMutation = { __typename?: 'Mutation', track: { __typename?: 'Analytics', success: boolean } };
export type AuthTokenFragmentFragment = { __typename?: 'AuthToken', token: string, expiresAt: string };
@ -1397,40 +1398,40 @@ export function useGetTimelineThreadsFromPersonIdLazyQuery(baseOptions?: Apollo.
export type GetTimelineThreadsFromPersonIdQueryHookResult = ReturnType<typeof useGetTimelineThreadsFromPersonIdQuery>;
export type GetTimelineThreadsFromPersonIdLazyQueryHookResult = ReturnType<typeof useGetTimelineThreadsFromPersonIdLazyQuery>;
export type GetTimelineThreadsFromPersonIdQueryResult = Apollo.QueryResult<GetTimelineThreadsFromPersonIdQuery, GetTimelineThreadsFromPersonIdQueryVariables>;
export const CreateEventDocument = gql`
mutation CreateEvent($type: String!, $data: JSON!) {
createEvent(type: $type, data: $data) {
export const TrackDocument = gql`
mutation Track($type: String!, $data: JSON!) {
track(type: $type, data: $data) {
success
}
}
`;
export type CreateEventMutationFn = Apollo.MutationFunction<CreateEventMutation, CreateEventMutationVariables>;
export type TrackMutationFn = Apollo.MutationFunction<TrackMutation, TrackMutationVariables>;
/**
* __useCreateEventMutation__
* __useTrackMutation__
*
* To run a mutation, you first call `useCreateEventMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useCreateEventMutation` returns a tuple that includes:
* To run a mutation, you first call `useTrackMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useTrackMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [createEventMutation, { data, loading, error }] = useCreateEventMutation({
* const [trackMutation, { data, loading, error }] = useTrackMutation({
* variables: {
* type: // value for 'type'
* data: // value for 'data'
* },
* });
*/
export function useCreateEventMutation(baseOptions?: Apollo.MutationHookOptions<CreateEventMutation, CreateEventMutationVariables>) {
export function useTrackMutation(baseOptions?: Apollo.MutationHookOptions<TrackMutation, TrackMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<CreateEventMutation, CreateEventMutationVariables>(CreateEventDocument, options);
return Apollo.useMutation<TrackMutation, TrackMutationVariables>(TrackDocument, options);
}
export type CreateEventMutationHookResult = ReturnType<typeof useCreateEventMutation>;
export type CreateEventMutationResult = Apollo.MutationResult<CreateEventMutation>;
export type CreateEventMutationOptions = Apollo.BaseMutationOptions<CreateEventMutation, CreateEventMutationVariables>;
export type TrackMutationHookResult = ReturnType<typeof useTrackMutation>;
export type TrackMutationResult = Apollo.MutationResult<TrackMutation>;
export type TrackMutationOptions = Apollo.BaseMutationOptions<TrackMutation, TrackMutationVariables>;
export const ChallengeDocument = gql`
mutation Challenge($email: String!, $password: String!) {
challenge(email: $email, password: $password) {

View File

@ -1,9 +0,0 @@
import { gql } from '@apollo/client';
export const CREATE_EVENT = gql`
mutation CreateEvent($type: String!, $data: JSON!) {
createEvent(type: $type, data: $data) {
success
}
}
`;

View File

@ -0,0 +1,9 @@
import { gql } from '@apollo/client';
export const TRACK = gql`
mutation Track($type: String!, $data: JSON!) {
track(type: $type, data: $data) {
success
}
}
`;

View File

@ -11,8 +11,8 @@ const mocks: MockedResponse[] = [
{
request: {
query: gql`
mutation CreateEvent($type: String!, $data: JSON!) {
createEvent(type: $type, data: $data) {
mutation Track($type: String!, $data: JSON!) {
track(type: $type, data: $data) {
success
}
}
@ -24,7 +24,7 @@ const mocks: MockedResponse[] = [
},
result: jest.fn(() => ({
data: {
createEvent: {
track: {
success: true,
},
},

View File

@ -4,10 +4,10 @@ import { RecoilRoot } from 'recoil';
import { useTrackEvent } from '../useTrackEvent';
const mockCreateEventMutation = jest.fn();
const mockTrackMutation = jest.fn();
jest.mock('~/generated/graphql', () => ({
useCreateEventMutation: () => [mockCreateEventMutation],
useTrackMutation: () => [mockTrackMutation],
}));
describe('useTrackEvent', () => {
@ -17,8 +17,8 @@ describe('useTrackEvent', () => {
renderHook(() => useTrackEvent(eventType, eventData), {
wrapper: RecoilRoot,
});
expect(mockCreateEventMutation).toHaveBeenCalledTimes(1);
expect(mockCreateEventMutation).toHaveBeenCalledWith({
expect(mockTrackMutation).toHaveBeenCalledTimes(1);
expect(mockTrackMutation).toHaveBeenCalledWith({
variables: { type: eventType, data: eventData },
});
});

View File

@ -2,7 +2,7 @@ import { useCallback } from 'react';
import { useRecoilValue } from 'recoil';
import { telemetryState } from '@/client-config/states/telemetryState';
import { useCreateEventMutation } from '~/generated/graphql';
import { useTrackMutation } from '~/generated/graphql';
interface EventLocation {
pathname: string;
@ -14,7 +14,7 @@ export interface EventData {
export const useEventTracker = () => {
const telemetry = useRecoilValue(telemetryState());
const [createEventMutation] = useCreateEventMutation();
const [createEventMutation] = useTrackMutation();
return useCallback(
(eventType: string, eventData: EventData) => {

View File

@ -77,8 +77,8 @@ describe('useApolloFactory', () => {
await act(async () => {
await result.current.factory.mutate({
mutation: gql`
mutation CreateEvent($type: String!, $data: JSON!) {
createEvent(type: $type, data: $data) {
mutation Track($type: String!, $data: JSON!) {
track(type: $type, data: $data) {
success
}
}

View File

@ -41,8 +41,8 @@ const makeRequest = async () => {
await client.mutate({
mutation: gql`
mutation CreateEvent($type: String!, $data: JSON!) {
createEvent(type: $type, data: $data) {
mutation Track($type: String!, $data: JSON!) {
track(type: $type, data: $data) {
success
}
}

View File

@ -1,4 +1,5 @@
export type FeatureFlagKey =
| 'IS_BLOCKLIST_ENABLED'
| 'IS_CALENDAR_ENABLED'
| 'IS_QUICK_ACTIONS_ENABLED';
| 'IS_QUICK_ACTIONS_ENABLED'
| 'IS_EVENT_OBJECT_ENABLED';

View File

@ -1,7 +1,7 @@
import { getOperationName } from '@apollo/client/utilities';
import { graphql, HttpResponse } from 'msw';
import { CREATE_EVENT } from '@/analytics/graphql/queries/createEvent';
import { TRACK } from '@/analytics/graphql/queries/track';
import { GET_CLIENT_CONFIG } from '@/client-config/graphql/queries/getClientConfig';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '@/object-metadata/graphql/queries';
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
@ -31,10 +31,10 @@ export const graphqlMocks = {
},
});
}),
graphql.mutation(getOperationName(CREATE_EVENT) ?? '', () => {
graphql.mutation(getOperationName(TRACK) ?? '', () => {
return HttpResponse.json({
data: {
createEvent: { success: 1, __typename: 'Event' },
track: { success: 1, __typename: 'TRACK' },
},
});
}),