Skip to content

Commit e6fb4a2

Browse files
authored
Merge pull request #37 from relay-tools/relay-modern
Support Relay Modern
2 parents d43d5a1 + abec42f commit e6fb4a2

19 files changed

+189
-103
lines changed

.babelrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"presets": [
3-
["es2015", { "loose": true }]
3+
["latest", {
4+
"es2015": { "loose": true }
5+
}],
6+
"stage-1"
47
],
58
"plugins": ["add-module-exports"]
69
}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ build/Release
2626
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
2727
node_modules
2828

29-
# Transpiled code
29+
# Transpiled code.
3030
/lib
31+
32+
# Generated files.
33+
__generated__

.travis.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
sudo: false
1+
# We need sudo to properly install Watchman.
2+
sudo: required
23

34
language: node_js
45
node_js:
56
- stable
67

7-
env:
8-
- BROWSER=ChromeCi
9-
- BROWSER=Firefox
10-
118
cache:
129
directories:
1310
- node_modules
1411

1512
before_install:
16-
- export CHROME_BIN=chromium-browser
17-
- export DISPLAY=:99.0
18-
- sh -e /etc/init.d/xvfb start
13+
# Relay Compiler requires Watchman.
14+
# TODO: Cache this? The Watchman build is pretty quick, though.
15+
- git clone https://github.com/facebook/watchman.git ~/facebook/watchman
16+
- pushd ~/facebook/watchman
17+
- git checkout v4.7.0
18+
- ./autogen.sh && ./configure && make && sudo make install
19+
- popd
1920

2021
branches:
2122
only:

README.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
1-
# relay-local-schema [![Travis][build-badge]][build] [![npm][npm-badge]][npm]
1+
# Relay Local Schema [![Travis][build-badge]][build] [![npm][npm-badge]][npm]
22
Use [Relay](http://facebook.github.io/relay/) without a GraphQL server.
33

44
[![Discord][discord-badge]][discord]
55

66
## Usage
77

8-
Use `RelayLocalSchema.NetworkLayer` to execute GraphQL queries locally, rather than against a separate GraphQL server.
8+
### Relay Modern
99

10-
This is intended for exploratory work, integration tests, demos, and working with local data. This is not generally intended as a substitute for a remote backend, except possibly when using local data as a persistent cache.
10+
```js
11+
import { Network } from 'relay-local-schema';
12+
13+
import schema from './data/schema';
14+
15+
const environment = new Environment({
16+
network: Network.create({ schema }),
17+
/* ... */
18+
});
19+
```
20+
21+
This will execute queries against the specified schema locally, rather than against a separate GraphQL server.
22+
23+
You can also specify a GraphQL.js `rootValue` or `contextValue`:
24+
25+
```js
26+
const environment = new Environment({
27+
network: Network.create({
28+
schema,
29+
rootValue: 'foo',
30+
contextValue: 'bar',
31+
}),
32+
/* ... */
33+
});
34+
```
35+
36+
### Relay Classic
1137

1238
```js
13-
import RelayLocalSchema from 'relay-local-schema';
39+
import RelayLocalSchema from 'relay-local-schema/lib/classic';
1440

1541
import schema from './data/schema';
1642

@@ -19,19 +45,25 @@ Relay.injectNetworkLayer(
1945
);
2046
```
2147

22-
You can also supply a GraphQL.js `rootValue` or an `onError` callback to the
23-
constructor:
48+
This will execute queries against the specified schema locally, rather than against a separate GraphQL server.
49+
50+
You can also supply a GraphQL.js `rootValue` or `contextValue`, or an `onError` callback:
2451

2552
```js
2653
Relay.injectNetworkLayer(
2754
new RelayLocalSchema.NetworkLayer({
2855
schema,
2956
rootValue: 'foo',
57+
contextValue: 'bar',
3058
onError: (errors, request) => console.error(errors, request),
3159
})
3260
);
3361
```
3462

63+
## Caveat
64+
65+
This is intended for exploratory work, integration tests, demos, and working with local data. This is not generally intended as a substitute for a remote GraphQL back end in production.
66+
3567
[build-badge]: https://img.shields.io/travis/relay-tools/relay-local-schema/master.svg
3668
[build]: https://travis-ci.org/relay-tools/relay-local-schema
3769

karma.conf.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

package.json

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
"main": "lib/index.js",
99
"scripts": {
1010
"build": "rimraf lib && babel src -d lib",
11-
"build-fixtures": "babel-node test/fixtures/updateSchema.js",
11+
"build-fixtures": "npm run update-schema && npm run relay-compiler",
1212
"lint": "eslint src test *.js",
1313
"prepublish": "npm run build",
14-
"tdd": "karma start",
14+
"relay-compiler": "relay-compiler --src test/modern --schema test/fixtures/schema.graphql",
15+
"tdd": "jest --watch",
1516
"test": "npm run build-fixtures && npm run lint && npm run testonly",
16-
"testonly": "npm run tdd -- --single-run"
17+
"testonly": "jest --runInBand --verbose",
18+
"update-schema": "babel-node test/fixtures/updateSchema.js"
1719
},
1820
"repository": {
1921
"type": "git",
@@ -30,45 +32,35 @@
3032
"url": "https://github.com/relay-tools/relay-local-schema/issues"
3133
},
3234
"homepage": "https://github.com/relay-tools/relay-local-schema#readme",
35+
"dependencies": {
36+
"relay-runtime": "^1.0.0"
37+
},
3338
"peerDependencies": {
3439
"graphql": ">=0.5.0",
3540
"react-relay": ">=0.8.0"
3641
},
3742
"devDependencies": {
3843
"babel-cli": "^6.24.1",
39-
"babel-core": "^6.24.1",
4044
"babel-eslint": "^7.2.3",
41-
"babel-loader": "^7.0.0",
45+
"babel-jest": "^20.0.3",
4246
"babel-plugin-add-module-exports": "^0.2.1",
4347
"babel-plugin-relay": "^1.0.1",
4448
"babel-polyfill": "^6.23.0",
45-
"babel-preset-es2015": "^6.24.1",
4649
"babel-preset-latest": "^6.24.1",
4750
"babel-preset-react": "^6.24.1",
48-
"babel-preset-stage-2": "^6.24.1",
49-
"chai": "^3.5.0",
51+
"babel-preset-stage-1": "^6.24.1",
5052
"eslint": "^3.19.0",
5153
"eslint-config-4catalyzer-react": "^0.2.0",
5254
"eslint-plugin-import": "^2.3.0",
5355
"eslint-plugin-jsx-a11y": "^2.2.3",
5456
"eslint-plugin-react": "^6.7.1",
5557
"graphql": "^0.10.1",
5658
"graphql-relay": "^0.5.1",
57-
"karma": "^1.7.0",
58-
"karma-chrome-launcher": "^2.1.1",
59-
"karma-firefox-launcher": "^1.0.1",
60-
"karma-mocha": "^1.3.0",
61-
"karma-mocha-reporter": "^2.2.3",
62-
"karma-sinon-chai": "^1.3.1",
63-
"karma-sourcemap-loader": "^0.3.7",
64-
"karma-webpack": "^2.0.3",
65-
"mocha": "^3.4.2",
59+
"jest": "^20.0.4",
6660
"react": "^15.5.4",
6761
"react-dom": "^15.5.4",
6862
"react-relay": "^1.0.0",
69-
"rimraf": "^2.6.1",
70-
"sinon": "^2.3.2",
71-
"sinon-chai": "^2.10.0",
72-
"webpack": "^2.6.1"
63+
"relay-compiler": "^1.0.0",
64+
"rimraf": "^2.6.1"
7365
}
7466
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/classic/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import NetworkLayer from './NetworkLayer';
2+
3+
export default { NetworkLayer };

0 commit comments

Comments
 (0)