Skip to content

Commit

Permalink
Extract events into named types (#4254)
Browse files Browse the repository at this point in the history
Summary:
Being able to refine log events to named types in tests would be very helpful, so I've(?) refactored the union of log events to be a union of named types.

This refactor brought to you by ChatGPT.

Prompt:

> Can you refactor this Flow code to extract each log event type into its own named type, with the LogEvent type being a union of those types?

Took a few tries because the output was longer than it could emit as one response:

> Can you do the last ones, starting with StorePublishLogEvent (and the resulting union of all named types)

Pull Request resolved: #4254

Reviewed By: rbalicki2

Differential Revision: D44263920

Pulled By: captbaritone

fbshipit-source-id: dc2c0a9bc3e3de89656fefdfe770d3b4b595de36
  • Loading branch information
captbaritone authored and facebook-github-bot committed Mar 21, 2023
1 parent 3073f1e commit e43a369
Showing 1 changed file with 209 additions and 157 deletions.
366 changes: 209 additions & 157 deletions packages/relay-runtime/store/RelayStoreTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,164 +534,216 @@ export interface RecordSourceSelectorProxy extends RecordSourceProxy {
invalidateStore(): void;
}

export type SuspenseFragmentLogEvent = {
+name: 'suspense.fragment',
+data: mixed,
+fragment: ReaderFragment,
+isRelayHooks: boolean,
+isMissingData: boolean,
+isPromiseCached: boolean,
+pendingOperations: $ReadOnlyArray<RequestDescriptor>,
};

export type SuspenseQueryLogEvent = {
+name: 'suspense.query',
+fetchPolicy: string,
+isPromiseCached: boolean,
+operation: OperationDescriptor,
+queryAvailability: ?OperationAvailability,
+renderPolicy: RenderPolicy,
};

export type QueryResourceFetchLogEvent = {
+name: 'queryresource.fetch',
// ID of this query resource request and will be the same
// if there is an associated queryresource.retain event.
+resourceID: number,
+operation: OperationDescriptor,
// value from ProfilerContext
+profilerContext: mixed,
// FetchPolicy from Relay Hooks
+fetchPolicy: string,
// RenderPolicy from Relay Hooks
+renderPolicy: RenderPolicy,
+queryAvailability: OperationAvailability,
+shouldFetch: boolean,
};
export type QueryResourceRetainLogEvent = {
+name: 'queryresource.retain',
+resourceID: number,
// value from ProfilerContext
+profilerContext: mixed,
};
export type FragmentResourceMissingDataLogEvent = {
// Indicates FragmentResource is going to return a result that is missing
// data.
+name: 'fragmentresource.missing_data',
+data: mixed,
+fragment: ReaderFragment,
+isRelayHooks: boolean,
// Are we reading this result from the fragment resource cache?
+cached: boolean,
};
export type PendingOperationFoundLogEvent = {
// Indicates getPendingOperationForFragment identified a pending operation.
// Useful for measuring how frequently RelayOperationTracker identifies a
// related operation on which to suspend.
+name: 'pendingoperation.found',
+fragment: ReaderFragment,
+fragmentOwner: RequestDescriptor,
+pendingOperations: $ReadOnlyArray<RequestDescriptor>,
};
export type NetworkInfoLogEvent = {
+name: 'network.info',
+networkRequestId: number,
+info: mixed,
};
export type NetworkStartLogEvent = {
+name: 'network.start',
+networkRequestId: number,
+params: RequestParameters,
+variables: Variables,
+cacheConfig: CacheConfig,
};
export type NetworkNextLogEvent = {
+name: 'network.next',
+networkRequestId: number,
+response: GraphQLResponse,
};
export type NetworkErrorLogEvent = {
+name: 'network.error',
+networkRequestId: number,
+error: Error,
};
export type NetworkCompleteLogEvent = {
+name: 'network.complete',
+networkRequestId: number,
};
export type NetworkUnsubscribeLogEvent = {
+name: 'network.unsubscribe',
+networkRequestId: number,
};
export type ExecuteStartLogEvent = {
+name: 'execute.start',
+executeId: number,
+params: RequestParameters,
+variables: Variables,
+cacheConfig: CacheConfig,
};
export type ExecuteNextLogEvent = {
+name: 'execute.next',
+executeId: number,
+response: GraphQLResponse,
+duration: number,
};
export type ExecuteAsyncModuleLogEvent = {
+name: 'execute.async.module',
+executeId: number,
+operationName: string,
+duration: number,
};
export type ExecuteFlightPayloadDeserializeLogEvent = {
+name: 'execute.flight.payload_deserialize',
+executeId: number,
+operationName: string,
+duration: number,
};
export type ExecuteErrorLogEvent = {
+name: 'execute.error',
+executeId: number,
+error: Error,
};
export type ExecuteCompleteLogEvent = {
+name: 'execute.complete',
+executeId: number,
};
export type StorePublishLogEvent = {
+name: 'store.publish',
+source: RecordSource,
+optimistic: boolean,
};
export type StoreSnapshotLogEvent = {
+name: 'store.snapshot',
};
export type StoreRestoreLogEvent = {
+name: 'store.restore',
};
export type StoreGcLogEvent = {
+name: 'store.gc',
+references: DataIDSet,
};
export type StoreNotifyStartLogEvent = {
+name: 'store.notify.start',
+sourceOperation: ?OperationDescriptor,
};
export type StoreNotifyCompleteLogEvent = {
+name: 'store.notify.complete',
+sourceOperation: ?OperationDescriptor,
+updatedRecordIDs: DataIDSet,
+invalidatedRecordIDs: DataIDSet,
};
export type StoreNotifySubscriptionLogEvent = {
+name: 'store.notify.subscription',
+sourceOperation: ?OperationDescriptor,
+snapshot: Snapshot,
+nextSnapshot: Snapshot,
};
export type EntrypointRootConsumeLogEvent = {
+name: 'entrypoint.root.consume',
+profilerContext: mixed,
+rootModuleID: string,
};
export type LogEvent =
| {
+name: 'suspense.fragment',
+data: mixed,
+fragment: ReaderFragment,
+isRelayHooks: boolean,
+isMissingData: boolean,
+isPromiseCached: boolean,
+pendingOperations: $ReadOnlyArray<RequestDescriptor>,
}
| {
+name: 'suspense.query',
+fetchPolicy: string,
+isPromiseCached: boolean,
+operation: OperationDescriptor,
+queryAvailability: ?OperationAvailability,
+renderPolicy: RenderPolicy,
}
| {
+name: 'queryresource.fetch',
// ID of this query resource request and will be the same
// if there is an associated queryresource.retain event.
+resourceID: number,
+operation: OperationDescriptor,
// value from ProfilerContext
+profilerContext: mixed,
// FetchPolicy from Relay Hooks
+fetchPolicy: string,
// RenderPolicy from Relay Hooks
+renderPolicy: RenderPolicy,
+queryAvailability: OperationAvailability,
+shouldFetch: boolean,
}
| {
+name: 'queryresource.retain',
+resourceID: number,
// value from ProfilerContext
+profilerContext: mixed,
}
| {
// Indicates FragmentResource is going to return a result that is missing
// data.
+name: 'fragmentresource.missing_data',
+data: mixed,
+fragment: ReaderFragment,
+isRelayHooks: boolean,
// Are we reading this result from the fragment resource cache?
+cached: boolean,
}
| {
// Indicates getPendingOperationForFragment identified a pending operation.
// Useful for measuring how frequently RelayOperationTracker identifies a
// related operation on which to suspend.
+name: 'pendingoperation.found',
+fragment: ReaderFragment,
+fragmentOwner: RequestDescriptor,
+pendingOperations: $ReadOnlyArray<RequestDescriptor>,
}
| {
+name: 'network.info',
+networkRequestId: number,
+info: mixed,
}
| {
+name: 'network.start',
+networkRequestId: number,
+params: RequestParameters,
+variables: Variables,
+cacheConfig: CacheConfig,
}
| {
+name: 'network.next',
+networkRequestId: number,
+response: GraphQLResponse,
}
| {
+name: 'network.error',
+networkRequestId: number,
+error: Error,
}
| {
+name: 'network.complete',
+networkRequestId: number,
}
| {
+name: 'network.unsubscribe',
+networkRequestId: number,
}
| {
+name: 'execute.start',
+executeId: number,
+params: RequestParameters,
+variables: Variables,
+cacheConfig: CacheConfig,
}
| {
+name: 'execute.next',
+executeId: number,
+response: GraphQLResponse,
+duration: number,
}
| {
+name: 'execute.async.module',
+executeId: number,
+operationName: string,
+duration: number,
}
| {
+name: 'execute.flight.payload_deserialize',
+executeId: number,
+operationName: string,
+duration: number,
}
| {
+name: 'execute.error',
+executeId: number,
+error: Error,
}
| {
+name: 'execute.complete',
+executeId: number,
}
| {
+name: 'store.publish',
+source: RecordSource,
+optimistic: boolean,
}
| {
+name: 'store.snapshot',
}
| {
+name: 'store.restore',
}
| {
+name: 'store.gc',
+references: DataIDSet,
}
| {
+name: 'store.notify.start',
+sourceOperation: ?OperationDescriptor,
}
| {
+name: 'store.notify.complete',
+sourceOperation: ?OperationDescriptor,
+updatedRecordIDs: DataIDSet,
+invalidatedRecordIDs: DataIDSet,
}
| {
+name: 'store.notify.subscription',
+sourceOperation: ?OperationDescriptor,
+snapshot: Snapshot,
+nextSnapshot: Snapshot,
}
| {
+name: 'entrypoint.root.consume',
+profilerContext: mixed,
+rootModuleID: string,
};
| SuspenseFragmentLogEvent
| SuspenseQueryLogEvent
| QueryResourceFetchLogEvent
| QueryResourceRetainLogEvent
| FragmentResourceMissingDataLogEvent
| PendingOperationFoundLogEvent
| NetworkInfoLogEvent
| NetworkStartLogEvent
| NetworkNextLogEvent
| NetworkErrorLogEvent
| NetworkCompleteLogEvent
| NetworkUnsubscribeLogEvent
| ExecuteStartLogEvent
| ExecuteNextLogEvent
| ExecuteAsyncModuleLogEvent
| ExecuteFlightPayloadDeserializeLogEvent
| ExecuteErrorLogEvent
| ExecuteCompleteLogEvent
| StorePublishLogEvent
| StoreSnapshotLogEvent
| StoreRestoreLogEvent
| StoreGcLogEvent
| StoreNotifyStartLogEvent
| StoreNotifyCompleteLogEvent
| StoreNotifySubscriptionLogEvent
| EntrypointRootConsumeLogEvent;
export type LogFunction = LogEvent => void;
export type LogRequestInfoFunction = mixed => void;
Expand Down

0 comments on commit e43a369

Please sign in to comment.