UNPKG

rescript-relay

Version:
81 lines (71 loc) 3.04 kB
// Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; let React = require("react"); let ReactRelay = require("react-relay"); let RelayRuntime = require("relay-runtime"); let Primitive_option = require("@rescript/runtime/lib/js/Primitive_option.js"); let RescriptRelay_Internal = require("./RescriptRelay_Internal.bs.js"); function useQuery(convertVariables, node, convertResponse) { return (variables, fetchPolicy, fetchKey, networkCacheConfig) => RescriptRelay_Internal.internal_useConvertedValue(convertResponse, ReactRelay.useLazyLoadQuery(node, RescriptRelay_Internal.internal_cleanObjectFromUndefinedRaw(convertVariables(variables)), { fetchKey: fetchKey, fetchPolicy: fetchPolicy, networkCacheConfig: networkCacheConfig })); } function useLoader(convertVariables, node, mkQueryRef) { return () => { let match = ReactRelay.useQueryLoader(node); let loadQueryFn = match[1]; let loadQuery = React.useMemo(() => ((variables, fetchPolicy, networkCacheConfig) => loadQueryFn(convertVariables(variables), { fetchPolicy: fetchPolicy, networkCacheConfig: networkCacheConfig })), [loadQueryFn]); return [ mkQueryRef(Primitive_option.fromNullable(match[0])), loadQuery, match[2] ]; }; } function usePreloaded(node, convertResponse, mkQueryRef) { return queryRef => RescriptRelay_Internal.internal_useConvertedValue(convertResponse, ReactRelay.usePreloadedQuery(node, mkQueryRef(queryRef))); } function fetch(node, convertResponse, convertVariables) { return (environment, variables, onResult, networkCacheConfig, fetchPolicy) => { ReactRelay.fetchQuery(environment, node, convertVariables(variables), { networkCacheConfig: networkCacheConfig, fetchPolicy: fetchPolicy }).subscribe({ next: res => onResult({ TAG: "Ok", _0: convertResponse(res) }), error: err => onResult({ TAG: "Error", _0: err }) }); }; } function fetchPromised(node, convertResponse, convertVariables) { return (environment, variables, networkCacheConfig, fetchPolicy) => ReactRelay.fetchQuery(environment, node, convertVariables(variables), { networkCacheConfig: networkCacheConfig, fetchPolicy: fetchPolicy }).toPromise().then(res => Promise.resolve(convertResponse(res))); } function retain(node, convertVariables) { return (environment, variables) => environment.retain(RelayRuntime.createOperationDescriptor(node, convertVariables(variables))); } function commitLocalPayload(node, convertVariables, convertWrapRawResponse) { return (environment, variables, payload) => { environment.commitPayload(RelayRuntime.createOperationDescriptor(node, convertVariables(variables)), convertWrapRawResponse(payload)); }; } exports.useQuery = useQuery; exports.useLoader = useLoader; exports.usePreloaded = usePreloaded; exports.fetch = fetch; exports.fetchPromised = fetchPromised; exports.retain = retain; exports.commitLocalPayload = commitLocalPayload; /* react Not a pure module */