[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:
Vinh
2019-06-07 21:42:26 +00:00
committed by Wyatt Johnson
parent ed4e5fa2a8
commit d4b99a2a57
38 changed files with 682 additions and 929 deletions
@@ -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");
});
}
+13 -1
View File
@@ -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>) => {