How to use the relay-runtime.getDataIDsFromObject function in relay-runtime

To help you get started, we’ve selected a few relay-runtime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / relay / packages / relay-experimental / renderers / createSuspenseFragmentContainer.js View on Github external
componentDidUpdate(prevProps: InternalProps) {
      // TODO Check if data has changed between render and update. Schedule another
      // update if so
      const mustResubscribe =
        prevProps.relayContext !== this.props.relayContext ||
        !areEqual(
          getDataIDsFromObject(fragmentNodes, prevProps.fragmentRefs),
          getDataIDsFromObject(fragmentNodes, this.props.fragmentRefs),
        );

      if (mustResubscribe) {
        this._unsubscribe();
        this._subscribe();
      }
    }
github facebook / relay / packages / react-relay / ReactRelayPaginationContainer.js View on Github external
UNSAFE_componentWillReceiveProps(nextProps) {
      const relayContext = assertRelayContext(nextProps.__relayContext);
      const prevIDs = getDataIDsFromObject(fragments, this.props);
      const nextIDs = getDataIDsFromObject(fragments, nextProps);

      // If the environment has changed or props point to new records then
      // previously fetched data and any pending fetches no longer apply:
      // - Existing references are on the old environment.
      // - Existing references are based on old variables.
      // - Pending fetches are for the previous records.
      if (
        relayContext.environment !== this.state.prevContext.environment ||
        !areEqual(prevIDs, nextIDs)
      ) {
        this._cleanup();
        // Child containers rely on context.relay being mutated (for gDSFP).
        this._resolver = createFragmentSpecResolver(
          relayContext,
          containerName,
github facebook / relay / packages / react-relay / ReactRelayFragmentContainer.js View on Github external
static getDerivedStateFromProps(
      nextProps: ContainerProps,
      prevState: ContainerState,
    ): $Shape | null {
      // Any props change could impact the query, so we mirror props in state.
      // This is an unusual pattern, but necessary for this container usecase.
      const {prevProps} = prevState;
      const relayContext = assertRelayContext(nextProps.__relayContext);
      const prevIDs = getDataIDsFromObject(fragments, prevProps);
      const nextIDs = getDataIDsFromObject(fragments, nextProps);

      let resolver: FragmentSpecResolver = prevState.resolver;

      // If the environment has changed or props point to new records then
      // previously fetched data and any pending fetches no longer apply:
      // - Existing references are on the old environment.
      // - Existing references are based on old variables.
      // - Pending fetches are for the previous records.
      if (
        prevState.prevPropsContext.environment !== relayContext.environment ||
        !areEqual(prevIDs, nextIDs)
      ) {
        // Do not provide a subscription/callback here.
        // It is possible for this render to be interrupted or aborted,
        // In which case the subscription would cause a leak.
        // We will add the subscription in componentDidUpdate().
github ntkme / vue-relay / src / VueRelayFragmentContainer.js View on Github external
getDerivedStateFromProps (nextProps, prevState) {
        // Any props change could impact the query, so we mirror props in state.
        // This is an unusual pattern, but necessary for this container usecase.
        const { prevProps } = prevState
        const relayContext = assertRelayContext(nextProps.__relayContext)
        const prevIDs = getDataIDsFromObject(fragments, prevProps)
        const nextIDs = getDataIDsFromObject(fragments, nextProps)

        let resolver = prevState.resolver

        // If the environment has changed or props point to new records then
        // previously fetched data and any pending fetches no longer apply:
        // - Existing references are on the old environment.
        // - Existing references are based on old variables.
        // - Pending fetches are for the previous records.
        if (
          prevState.prevPropsContext.environment !== relayContext.environment ||
          prevState.prevPropsContext.variables !== relayContext.variables ||
          !areEqual(prevIDs, nextIDs)
        ) {
          // Do not provide a subscription/callback here.
          // It is possible for this render to be interrupted or aborted,
github ntkme / vue-relay / dist / vue-relay.esm.js View on Github external
getDerivedStateFromProps: function getDerivedStateFromProps(nextProps, prevState) {
        // Any props change could impact the query, so we mirror props in state.
        // This is an unusual pattern, but necessary for this container usecase.
        var prevProps = prevState.prevProps;
        var relayContext = assertRelayContext(nextProps.__relayContext);
        var prevIDs = getDataIDsFromObject(fragments, prevProps);
        var nextIDs = getDataIDsFromObject(fragments, nextProps); // If the environment has changed or props point to new records then
        // previously fetched data and any pending fetches no longer apply:
        // - Existing references are on the old environment.
        // - Existing references are based on old variables.
        // - Pending fetches are for the previous records.

        if (prevState.prevPropsContext.environment !== relayContext.environment || prevState.prevPropsContext.variables !== relayContext.variables || !areEqual(prevIDs, nextIDs)) {
          this._cleanup(); // Child containers rely on context.relay being mutated (for gDSFP).


          this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, nextProps, this._handleFragmentDataUpdate);
          return {
            data: this._resolver.resolve(),
            prevProps: nextProps,
            prevPropsContext: relayContext,
            contextForChildren: relayContext,
            relayProp: this._buildRelayProp(relayContext)
github facebook / relay / packages / relay-experimental / renderers / DataResource.js View on Github external
function getFragmentCacheKey(
  fragmentNode: ConcreteFragment,
  fragmentRef: mixed,
  variables: Variables,
): string {
  const fragmentVariables = getVariablesFromObject(
    variables,
    {[fragmentNode.name]: fragmentNode},
    {[fragmentNode.name]: fragmentRef},
  );
  const dataIDs = getDataIDsFromObject(
    {[fragmentNode.name]: fragmentNode},
    {[fragmentNode.name]: fragmentRef},
  );
  return JSON.stringify({
    dataIDs,
    fragmentVariables,
  });
}
github facebook / relay / packages / relay-experimental / renderers / createSuspenseFragmentContainer.js View on Github external
static getDerivedStateFromProps(nextProps, prevState) {
      return {
        mirroredFragmentRefs: nextProps.fragmentRefs,
        mirroredRelayContext: nextProps.relayContext,
        mustResubscribe:
          prevState.mirroredRelayContext !== nextProps.relayContext ||
          !areEqual(
            getDataIDsFromObject(fragmentNodes, prevState.mirroredFragmentRefs),
            getDataIDsFromObject(fragmentNodes, nextProps.fragmentRefs),
          ),
      };
    }