How to use the relay-runtime.ConnectionInterface.get 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 / react-relay / classic / store / readRelayQueryData.js View on Github external
_readEdges(node: RelayQuery.Field, rangeInfo: RangeInfo, state: State): void {
    const {EDGES} = ConnectionInterface.get();

    if (rangeInfo.diffCalls.length) {
      state.isPartial = true;
    }
    const previousData = getDataValue(state, EDGES);
    // Include null-filtered edges as "seen" so that they will be subscribed.
    rangeInfo.requestedEdgeIDs.forEach(edgeID => {
      state.seenDataIDs[edgeID] = true;
    });
    const edges = rangeInfo.filteredEdges.map((edgeData, ii) => {
      let data;
      if (previousData instanceof Object) {
        data = previousData[ii];
      }
      const nextState = this._createState({
        componentDataID: null,
github relay-tools / relay-hooks / src / FragmentPagination.ts View on Github external
_getConnectionData(
        data: any,
    ): {
        cursor: string;
        edgeCount: number;
        hasMore: boolean;
    } {
        // Extract connection data and verify there are more edges to fetch
        const props = { ...data };
        const connectionData = this._getConnectionFromProps(props);
        if (connectionData == null) {
            return null;
        }
        const { EDGES, PAGE_INFO, HAS_NEXT_PAGE, HAS_PREV_PAGE, END_CURSOR, START_CURSOR } = ConnectionInterface.get();

        invariant(
            typeof connectionData === 'object',
            'ReactRelayPaginationContainer: Expected `getConnectionFromProps()` in `%s`' +
                'to return `null` or a plain object with %s and %s properties, got `%s`.',
            'useFragment pagination',
            EDGES,
            PAGE_INFO,
            connectionData,
        );
        const edges = connectionData[EDGES];
        const pageInfo = connectionData[PAGE_INFO];
        if (edges == null || pageInfo == null) {
            return null;
        }
        invariant(
github facebook / relay / packages / react-relay / classic / traversal / writeRelayUpdatePayload.js View on Github external
function mergeField(
  writer: RelayQueryWriter,
  fieldName: string,
  payload: PayloadObject | PayloadArray,
  operation: RelayQuery.Operation,
): void {
  // don't write mutation/subscription metadata fields
  const {CLIENT_MUTATION_ID} = ConnectionInterface.get();
  if (fieldName === 'error' || fieldName === CLIENT_MUTATION_ID) {
    return;
  }
  if (Array.isArray(payload)) {
    payload.forEach(item => {
      if (typeof item === 'object' && item != null && !Array.isArray(item)) {
        if (getString(item, ID)) {
          mergeField(writer, fieldName, item, operation);
        }
      }
    });
    return;
  }
  // reassign to preserve type information in below closure
  const payloadData = payload;
github facebook / relay / packages / react-relay / classic / mutation / RelayOptimisticMutationUtils.js View on Github external
function inferField(value: mixed, key: string): RelayQuery.Field {
  const {NODE, EDGES} = ConnectionInterface.get();

  const metadata = {
    canHaveSubselections: true,
    isPlural: false,
  };
  let children;
  if (Array.isArray(value)) {
    const element = value[0];
    if (element && typeof element === 'object') {
      children = RelayOptimisticMutationUtils.inferRelayFieldsFromData(element);
    } else {
      metadata.canHaveSubselections = false;
      children = [];
    }
    metadata.isPlural = true;
  } else if (typeof value === 'object' && value !== null) {
github facebook / relay / packages / relay-compiler / codegen / NormalizationCodeGenerator.js View on Github external
function generateConnection(
  schema: Schema,
  node: Connection,
): NormalizationConnection {
  const {EDGES, PAGE_INFO} = ConnectionInterface.get();
  const selections = generateSelections(schema, node.selections);
  let edges: ?NormalizationLinkedField;
  let pageInfo: ?NormalizationLinkedField;
  selections.forEach(selection => {
    if (selection.kind === 'LinkedField') {
      if (selection.name === EDGES) {
        edges = selection;
      } else if (selection.name === PAGE_INFO) {
        pageInfo = selection;
      }
    } else if (selection.kind === 'Stream') {
      selection.selections.forEach(subselection => {
        if (
          subselection.kind === 'LinkedField' &&
          subselection.name === EDGES
        ) {
github facebook / relay / packages / relay-compiler / transforms / ConnectionFieldTransform.js View on Github external
) {
      throw createUserError(
        "Invalid use of @connection_resolver, 'initial_count' is required " +
          "and must be an integer or variable of type 'Int!''.",
        [initialCountArg?.loc ?? connectionDirective.loc],
      );
    }
    stream = {
      deferLabel: label,
      initialCount: initialCountArg.value,
      if: ifArg != null ? ifArg.value : null,
      streamLabel: label,
    };
  }

  const {EDGES, PAGE_INFO} = ConnectionInterface.get();
  let edgeField: ?LinkedField;
  let pageInfoField: ?LinkedField;
  const selections = [];
  transformed.selections.forEach(selection => {
    if (
      !(selection.kind === 'LinkedField' || selection.kind === 'ScalarField')
    ) {
      throw createUserError(
        'Invalid use of @connection_resolver, selections on the connection ' +
          'must be linked or scalar fields.',
        [selection.loc],
      );
    }
    if (selection.kind === 'LinkedField') {
      if (selection.name === EDGES) {
        edgeField = selection;
github facebook / relay / packages / react-relay / classic / store / RelayStoreData.js View on Github external
handleUpdatePayload(
    operation: RelayQuery.Operation,
    payload: {[key: string]: mixed},
    {configs, isOptimisticUpdate}: UpdateOptions,
  ): void {
    const profiler = RelayProfiler.profile(
      'RelayStoreData.handleUpdatePayload',
    );
    const changeTracker = new RelayChangeTracker();
    let recordWriter;
    if (isOptimisticUpdate) {
      const {CLIENT_MUTATION_ID} = ConnectionInterface.get();

      const clientMutationID = payload[CLIENT_MUTATION_ID];
      invariant(
        typeof clientMutationID === 'string',
        'RelayStoreData.handleUpdatePayload(): Expected optimistic payload ' +
          'to have a valid `%s`.',
        CLIENT_MUTATION_ID,
      );
      recordWriter = this.getRecordWriterForOptimisticMutation(
        clientMutationID,
      );
    } else {
      recordWriter = this._getRecordWriterForMutation();
    }
    const writer = new RelayQueryWriter(
      this._queuedStore,
github facebook / relay / packages / react-relay / classic / traversal / intersectRelayQuery.js View on Github external
visitField(node: RelayQuery.Field): ?RelayQuery.Node {
    const {EDGES, PAGE_INFO} = ConnectionInterface.get();

    const schemaName = node.getSchemaName();
    if (schemaName === EDGES || schemaName === PAGE_INFO) {
      return null;
    } else {
      return node;
    }
  }
}
github facebook / relay / packages / react-relay / classic / mutation / RelayMutationQueue.js View on Github external
getInputVariable(): Variables {
    if (!this._inputVariable) {
      const inputVariable = {
        ...this.mutation.getVariables(),
        [ConnectionInterface.get().CLIENT_MUTATION_ID]: this.id,
      };
      this._inputVariable = inputVariable;
    }
    return this._inputVariable;
  }