Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test relay with easygraphql #53

Closed
sibelius opened this issue Jan 8, 2019 · 0 comments
Closed

test relay with easygraphql #53

sibelius opened this issue Jan 8, 2019 · 0 comments

Comments

@sibelius
Copy link
Member

sibelius commented Jan 8, 2019

https://gist.github.com/estrada9166/3cc30cece4d159228439298af7b41408

// @flow
/* global __DEV__ */
import fs from'fs';
import path from'path';
import EasyGraphQLTester from 'easygraphql-tester';

import { installRelayDevTools } from 'relay-devtools';
import { Environment, Network, RecordSource, Store } from 'relay-runtime';
import RelayNetworkLogger from 'relay-runtime/lib/RelayNetworkLogger';

import cacheHandler from './cacheHandler';
import { fixtures } from './fixture'

const schema = fs.readFileSync(path.join(__dirname, '..', '..', 'data',  'schema.graphql'), 'utf8');
const tester = new EasyGraphQLTester(schema);

let networkQuery = cacheHandler
if (__DEV__) {
  installRelayDevTools();
  networkQuery = RelayNetworkLogger.wrapFetch(cacheHandler)
}

// If it is a test set this variable or process.env.NODE_ENV === 'test'
if (__TEST__) {
  networkQuery = fetchQuery
}

function fetchQuery(operation, variables) {
  const mockedQuery = tester.mock({
    query: operation.text,
    variables,
    fixture: fixtures[operation.name]
  })
  console.log('Mocked Query: --->', mockedQuery);
  return mockedQuery.json()
}

const network = Network.create(networkQuery);

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

// export const inspector = new RecordSourceInspector(source);

const env = new Environment({
  network,
  store,
});

export default env;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant