store.getRootField (...) возвращает ноль - PullRequest
0 голосов
/ 29 сентября 2018

Я вызываю API для добавления нового запроса:

import { commitMutation, graphql } from "react-relay";

import { REQUEST_STATUS_NEW } from "../../../constants";

const mutation = graphql`
  mutation CreateRequestMutation($input: CreateRequestInput!) {
    createRequest(input: $input) {
      request {
        id
        tid
        title
        description
        price
        commission
        value
        expirationDate
        createdAt
        completionDate
        multipleResponders
        draft
        status
        requestProposals
        type {
          id
          name
        }
        industry {
          id
          name
        }
        applications {
          id
        }
        myApplication {
          id
        }
      }
    }
  }
`;

let tempId = 0;

function sharedUpdater(store, request) {
  const root = store.getRoot();
  const newRequests = root
    .getLinkedRecords("requests", { own: true })
    .filter(r => r);

  if (!newRequests.find(m => m.getValue("id") === request.getValue("id"))) {
    newRequests.push(request);
  }
  root.setLinkedRecords(newRequests, "requests", { own: true });
}

export const commit = (environment, input) => {
  tempId += 1;
  return commitMutation(environment, {
    mutation,
    variables: { input },
    updater: store => {
      const payload = store.getRootField("createRequest");
      console.log('payload: ', payload)
      const request = payload.getLinkedRecord("request");
      sharedUpdater(store, request);
    }
  });
};

Но каждый раз, когда я вызываю его, store.getRootField возвращает мне значение NULL.Я не могу понять, где проблема, где я могу продолжить расследование.Любая помощь приветствуется.Похоже, у сервера нет проблем на их стороне.Как я могу отладить это?

...