How to use the relay-runtime.RecordSource 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 sjchmiela / pokedex / src / services / createRelayEnvironment.js View on Github external
import { Environment, Network, RecordSource, Store } from "relay-runtime";
import * as AbsintheSocket from "@absinthe/socket";
import { createSubscriber } from "@absinthe/socket-relay";
import { Socket as PhoenixSocket } from "phoenix";

export const tokenKey = "token";

const source = new RecordSource();
const store = new Store(source);
const fetchQueryFactory = (customHeaders = {}) => (operation, variables) =>
  fetch("/graphql", {
    method: "POST",
    headers: {
      ...customHeaders,
      "content-type": "application/json",
    },
    body: JSON.stringify({
      query: operation.text, // GraphQL text from input
      variables,
    }),
  }).then(response => {
    return response.json();
  });
github OpenCTI-Platform / opencti / opencti-platform / opencti-front / src / relay / environment.js View on Github external
variables,
  });
}

const network = new RelayNetworkLayer(
  [
    urlMiddleware({
      url: `${APP_BASE_PATH}/graphql`,
      credentials: 'same-origin',
    }),
    uploadMiddleware(),
  ],
  { subscribeFn: networkSubscriptions },
);

const store = new Store(new RecordSource());
// Activate the read from store then network
// store.holdGC();
export const environment = new Environment({
  network,
  store,
});

// Components
export class QueryRenderer extends Component {
  render() {
    const {
      variables, query, render, managedErrorTypes,
    } = this.props;
    return (
github guigrpa / mady / src / client / gral / relay.js View on Github external
const createEnvironment = (
  records,
  fetchQuery = defaultFetchQuery,
  subscribe = defaultSubscribe
) => {
  const source = new Relay.RecordSource(records);
  const store = new Relay.Store(source);
  environment = new Relay.Environment({
    network:
      subscribe != null
        ? Relay.Network.create(fetchQuery, subscribe)
        : Relay.Network.create(fetchQuery),
    store,
  });
  // Debugging
  inspector =
    process.env.NODE_ENV !== 'production'
      ? new Relay.RecordSourceInspector(source)
      : null;
  return environment;
};
github relay-tools / found-relay / test / helpers.js View on Github external
export function createSyncEnvironment(fetch = createFakeFetch(), records) {
  return new Environment({
    network: Network.create(fetch),
    store: new Store(new RecordSource(records)),
  });
}
github coralproject / talk / src / core / client / framework / mutations / SetNetworkStatusMutation.spec.ts View on Github external
import { Environment, RecordSource } from "relay-runtime";

import { createRelayEnvironment } from "coral-framework/testHelpers";

import { NETWORK_ID, NETWORK_TYPE } from "../lib/relay/localState";
import { commit } from "./SetNetworkStatusMutation";

let environment: Environment;
const source: RecordSource = new RecordSource();

beforeAll(() => {
  environment = createRelayEnvironment({
    source,
    initLocalState: (localRecord, sourceProxy) => {
      const networkRecord = sourceProxy.create(NETWORK_ID, NETWORK_TYPE);
      networkRecord.setValue(false, "isOffline");
      localRecord.setLinkedRecord(networkRecord, "network");
    },
  });
});

it("Sets comment id", () => {
  commit(environment, { isOffline: true });
  expect(source.get(NETWORK_ID)!.isOffline).toEqual(true);
});
github coralproject / talk / src / core / client / stream / local / initLocalState.spec.ts View on Github external
beforeEach(() => {
  source = new RecordSource();
  environment = createRelayEnvironment({
    source,
    initLocalState: false,
  });
});
github ronal2do / RelayModern-Subscriptions-boilerplate / src / relay / Environment.js View on Github external
const onComplete = () =>
    observer.onCompleted()

  const client = subscriptionClient
    .request({ query, variables })
    .subscribe(onNext, onError, onComplete)

  return {
    dispose: client.unsubscribe,
  }
}

const network = Network.create(fetchQuery, setupSubscription)

const source = new RecordSource()
const store = new Store(source)

const environment = new Environment({
  network,
  store,
})

export default environment
github artsy / emission / src / lib / relay / createEnvironment.ts View on Github external
"Content-Type": "application/json",
        "User-Agent": Emission.userAgent,
        "X-USER-ID": Emission.userID,
        "X-ACCESS-TOKEN": Emission.authenticationToken,
        "X-TIMEZONE": Constants.LocalTimeZone,
      },
    }),
    loggerMiddleware(),
    errorMiddleware({
      disableServerMiddlewareTip: true,
    }),
    metaphysicsExtensionsLoggerMiddleware(),
    timingMiddleware(),
  ])

  const source = new RecordSource()
  const store = new Store(source)
  return new Environment({
    network,
    store,
  })
}
github damassi / isomorphic-relay-app / relay-modern / src / lib / isomorphic-relay / getRelayEnvironment.js View on Github external
export function getRelayEnvironment(records) {
  if (environment) {
    return environment
  }

  const source = new RecordSource(records)
  const store = new Store(source)

  environment = new Environment({
    network,
    store,
  })

  return environment
}
github hung-phan / koa-react-isomorphic / app / share / helpers / createApi.js View on Github external
export default () => {
  const fetcher = createFetcher();
  const environment = new Environment({
    network: Network.create(fetcher.fetch.bind(fetcher)),
    store: new Store(new RecordSource())
  });
  const resolver = new Resolver(environment);

  return {
    environment,
    resolver,
    fetcher,
    historyMiddlewares: [queryMiddleware],
    fetchQuery: fetchQuery.bind(undefined, environment),
    commitMutation: commitMutation.bind(undefined, environment),
    commitLocalUpdate: commitLocalUpdate.bind(undefined, environment)
  };
};