mirror of
https://github.com/wassname/talk.git
synced 2026-07-14 11:18:50 +08:00
[CORL-420] Upgrade Relay (#2346)
* chore: upgrade Relay * fix: fix errors * fix: snapshot * fix: relay prefix * fix: fragment spec error
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { Environment, RecordProxy, RecordSourceProxy } from "relay-runtime";
|
||||
|
||||
/**
|
||||
* Creates a Record and retain it forever.
|
||||
* This means that the garbage collector will
|
||||
* not remove the record on the next run.
|
||||
* Creates a Record and retain it forever. Useful for local state.
|
||||
* This means that the garbage collector will not remove the record
|
||||
* on the next run.
|
||||
*
|
||||
* See https://github.com/facebook/relay/issues/1656#issuecomment-380519761
|
||||
*/
|
||||
|
||||
@@ -18,9 +18,6 @@ export const LOCAL_TYPE = "Local";
|
||||
*/
|
||||
export const LOCAL_ID = "client:root.local";
|
||||
|
||||
export const NETWORK_TYPE = "Network";
|
||||
export const NETWORK_ID = "client:root.local.network";
|
||||
|
||||
export function setAccessTokenInLocalState(
|
||||
accessToken: string | null,
|
||||
source: RecordSourceProxy
|
||||
@@ -57,15 +54,5 @@ export async function initLocalBaseState(
|
||||
|
||||
// Set auth token
|
||||
setAccessTokenInLocalState(accessToken || null, s);
|
||||
|
||||
// Create network Record
|
||||
const networkRecord = createAndRetain(
|
||||
environment,
|
||||
s,
|
||||
NETWORK_ID,
|
||||
NETWORK_TYPE
|
||||
);
|
||||
networkRecord.setValue(false, "isOffline");
|
||||
localRecord.setLinkedRecord(networkRecord, "network");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,8 +23,20 @@ const createProxy = <T = any>(
|
||||
recordSource: RelayInMemoryRecordSource
|
||||
) => {
|
||||
const proxy: ProxyHandler<any> = {
|
||||
ownKeys() {
|
||||
return Object.keys(recordSource);
|
||||
},
|
||||
getOwnPropertyDescriptor() {
|
||||
return {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
};
|
||||
},
|
||||
has(_, prop) {
|
||||
return prop in recordSource;
|
||||
},
|
||||
get(_, prop) {
|
||||
if ((recordSource as any)[prop].__ref) {
|
||||
if (prop in recordSource && (recordSource as any)[prop].__ref) {
|
||||
return lookup(environment, (recordSource as any)[prop].__ref);
|
||||
}
|
||||
return (recordSource as any)[prop];
|
||||
|
||||
@@ -83,7 +83,10 @@ function applySimplified(
|
||||
function useLocal<T>(
|
||||
fragmentSpec: GraphQLTaggedNode
|
||||
): [OmitFragments<T>, (update: LocalUpdater<OmitFragments<T>>) => void] {
|
||||
const fragment = (fragmentSpec as any).data().default;
|
||||
const fragment =
|
||||
typeof fragmentSpec === "function"
|
||||
? fragmentSpec().default
|
||||
: (fragmentSpec as any).data().default;
|
||||
if (fragment.kind !== "Fragment") {
|
||||
throw new Error("Expected fragment");
|
||||
}
|
||||
@@ -106,7 +109,7 @@ function useLocal<T>(
|
||||
if (isAdvancedUpdater(update)) {
|
||||
update(record);
|
||||
} else {
|
||||
applySimplified(record, fragment.selections, update);
|
||||
applySimplified(record, fragment.selections[0].selections, update);
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -29,7 +29,10 @@ interface Props {
|
||||
function withLocalStateContainer(
|
||||
fragmentSpec: GraphQLTaggedNode
|
||||
): InferableComponentEnhancer<{ local: _RefType<any> }> {
|
||||
const fragment = (fragmentSpec as any).data().default;
|
||||
const fragment =
|
||||
typeof fragmentSpec === "function"
|
||||
? fragmentSpec().default
|
||||
: (fragmentSpec as any).data().default;
|
||||
return compose(
|
||||
withContext(({ relayEnvironment }) => ({ relayEnvironment })),
|
||||
hoistStatics((BaseComponent: React.ComponentType<any>) => {
|
||||
|
||||
Reference in New Issue
Block a user