Skip to content

Commit

Permalink
Squashed 'app/packages/meteor-integration/' changes from d5bee6f..853…
Browse files Browse the repository at this point in the history
…5ff5

8535ff5 Merge branch 'apollographql-master'
a0bcdeb updated to 0.3.1
9c0165b Release 0.3.1
8b17a20 Release 0.3.0
f2a6044 Update CHANGELOG
99d7c8c Add note to README about testing warning
0864876 Write tests for batching interface & restructure tests (#68)
624e46b Update versions
8677c36 Add batching (#62)
37497ea Enable SSR, fixes #56 (#57)
7eadb9d Fix #3 test runner (#63)
39d2c91 batching interface by default, extend interface option only when relevant
ec1e8cc client: allow to configure 'createMeteorNetworkInterface' to use  a batching interface; pass opts to fetch; add comments to default config

git-subtree-dir: app/packages/meteor-integration
git-subtree-split: 8535ff51a9b3ad39792903ea9259f956158d34e7
  • Loading branch information
cdmbase committed Feb 11, 2017
1 parent 55c3ac2 commit 89f1c1d
Show file tree
Hide file tree
Showing 15 changed files with 780 additions and 48 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": ["es2015", "stage-0"],
"plugins": [
"transform-runtime"
]
}
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/**
build/**
app/node_modules/**
packages/**
58 changes: 58 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"parser" : "babel-eslint",
"plugins": [
"react",
"jsx-a11y",
"import",
"meteor",
"fp",
"graphql"
],
"extends" : [
"airbnb",
"plugin:meteor/recommended"
],
"settings": {
"import/resolver": {
"meteor": {
"extensions": [
".js",
".jsx"
],
"moduleDirectory": [
"node_modules"
]
}
}
},
"rules": {
// Soft some rules.
"global-require": 0, // Used by webpack-isomorphic-tools and React Native.
"no-class-assign": 0, // Class assign is used for higher order components.
"no-nested-ternary": 0, // It's nice for JSX.
"no-param-reassign": 0, // We love param reassignment. Naming is hard.
"no-shadow": 0, // Shadowing is a nice language feature. Naming is hard.
"import/first": 0, // Este sorts by atom/sort-lines natural order.
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], // No, JSX belongs to .js files
"react/react-in-jsx-scope": 0,
"react/forbid-prop-types": [0, { "forbid": [] }],
"jsx-a11y/html-has-lang": 0, // Can't recognize the Helmet.
"no-confusing-arrow": 0, // This rule is super confusing.
"react/no-unused-prop-types": 0, // Este is going to use Flow types.
"react/jsx-indent": 0, // Damn. We need Yarn asap.
"import/prefer-default-export": 0, // No. Actions can have just one action.
"no-duplicate-imports": 0, // github.com/babel/eslint-plugin-babel/issues/59#issuecomment-230118848
"import/no-duplicates": 2,
// Rules for functional programming. We do not need Object.freeze.
"fp/no-mutating-assign": 2
// TODO: Can't be enabled now, it requires a lot of refactoring.
// "fp/no-mutating-methods": 2,
// "fp/no-mutation": ["error", {
// "commonjs": true,
// "allowThis": true,
// "exceptions": [
// {"property": "propTypes"}
// ]
// }]
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.idea
.iron
4 changes: 2 additions & 2 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
accounts-base@1.2.9
allow-deny@1.0.5
apollo@0.2.0
apollo@0.3.1
autoupdate@1.2.11
babel-compiler@6.9.0
babel-runtime@0.1.10
Expand Down Expand Up @@ -30,7 +30,7 @@ htmljs@1.0.10
http@1.1.8
id-map@1.0.8
jquery@1.11.9
local-test:apollo@0.2.0
local-test:apollo@0.3.1
localstorage@1.0.11
logging@1.1.14
meteor@1.2.16
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## vNEXT

## [0.3.1]
### Fixed

- Fixed bug in `v0.3.0` [#69](https://github.com/apollographql/meteor-integration/issues/69)

## [0.3.0] - 2017-02-08
AKA The Xavier Release 👍

### Updated

- `apollo-client` [`^0.7.0 || ^0.8.0'`](https://github.com/apollographql/apollo-client/blob/master/CHANGELOG.md#080)
- `apollo-server-express` [`^0.5.0`](https://github.com/apollographql/graphql-server/blob/master/CHANGELOG.md#v050)

### Added

- Export `createMeteorNetworkInterface` and `meteorClientConfig` server-side to allow server-side rendering, accept a `loginToken` option in the config of Apollo Client (for example the cookie from `meteorhacks:fast-render` used for SSR) [#57](https://github.com/apollostack/meteor-integration/pull/57)
- Tests! [#63](https://github.com/apollographql/meteor-integration/pull/63) and [#68](https://github.com/apollographql/meteor-integration/pull/68)

## [0.2.1] - 2016-12-23
### Added

Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
Use the [Apollo Stack](http://dev.apollodata.com/) in your [Meteor](https://www.meteor.com/) app.
Use the [Apollo GraphQL Client and Server](http://dev.apollodata.com/) in your [Meteor](https://www.meteor.com/) app.

```sh
meteor add apollo
```

# Docs

**[The docs](http://dev.apollodata.com/core/meteor.html)**

# Package dev

## Tests

TODO broken, see #3

```bash
git clone git@github.com:apollostack/meteor-integration.git
cd meteor-integration
meteor test-packages ./ --driver-package practicalmeteor:mocha
open localhost:3000
npm install
npm run test
open http://localhost:3000
```

Ignore the npm peer requirements warning that appears on client and server consoles.

## Credits

[Contributors](https://github.com/apollostack/meteor-integration/graphs/contributors)
14 changes: 7 additions & 7 deletions check-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { checkNpmVersions } from 'meteor/tmeasday:check-npm-versions';

if (Meteor.isClient) {
checkNpmVersions({
'apollo-client': '^0.5.0',
'apollo-client': '^0.7.0 || ^0.8.0',
}, 'apollo');
} else {
checkNpmVersions({
'graphql-server-express': '^0.4.3',
'graphql-server-express': '^0.6.0',
"body-parser": "^1.15.2",
"express": "^4.14.0",
"graphql": "^0.7.0 || ^0.8.0",
"graphql-tools": "^0.8.0",
"subscriptions-transport-ws": "^0.3.0",
"graphql-tag": "^1.1.0",
"graphql-subscriptions": "^0.2.0"
"graphql": "^0.8.0 || ^0.9.0",
"subscriptions-transport-ws": "^0.5.1",
"graphql-tag": "^1.1.2",
"graphql-subscriptions": "^0.3.0",
"graphql-tools": "^0.9.0 || 0.10.0",
}, 'apollo');
}
66 changes: 45 additions & 21 deletions main-client.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import './check-npm.js';

import { createNetworkInterface } from 'apollo-client';
import { createNetworkInterface, createBatchingNetworkInterface } from 'apollo-client';
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';
import { _ } from 'meteor/underscore';
import { print } from 'graphql-tag/printer';
import { Client } from 'subscriptions-transport-ws';

const defaultNetworkInterfaceConfig = {
path: '/graphql',
options: {},
useMeteorAccounts: true,
useSubscription: true,
path: '/graphql', // default graphql server endpoint
opts: {}, // additional fetch options like `credentials` or `headers`
useMeteorAccounts: true, // if true, send an eventual Meteor login token to identify the current user with every request
batchingInterface: true, // use a BatchingNetworkInterface by default instead of a NetworkInterface
batchInterval: 10, // default batch interval
};

const getDefaultWsClient = () => new Client('ws://localhost:8080');
Expand All @@ -24,14 +26,44 @@ export const createMeteorNetworkInterface = (givenConfig) => {
path = path.slice(1);
}

// For SSR
const uri = Meteor.absoluteUrl(path);
const networkInterface = createNetworkInterface({ uri });
// allow the use of a batching network interface; if the options.batchingInterface is not specified, fallback to the standard network interface
const interfaceToUse = config.batchingInterface ? createBatchingNetworkInterface : createNetworkInterface;

// default interface options
let interfaceOptions = {
uri: Meteor.absoluteUrl(path),
};

// if a BatchingNetworkInterface is used with a correct batch interval, add it to the options
if(config.batchingInterface && config.batchInterval) {
interfaceOptions.batchInterval = config.batchInterval;
}

// if 'fetch' has been configured to be called with specific opts, add it to the options
if(!_.isEmpty(config.opts)) {
interfaceOptions.opts = config.opts;
}

const networkInterface = interfaceToUse(interfaceOptions);

if (config.useMeteorAccounts) {
networkInterface.use([{
applyMiddleware(request, next) {
const currentUserToken = Accounts._storedLoginToken() ? Accounts._storedLoginToken() : null;

// cookie login token created by meteorhacks:fast-render and caught during server-side rendering by rr:react-router-ssr
const { loginToken: cookieLoginToken } = config;
// Meteor accounts-base login token stored in local storage, only exists client-side
const localStorageLoginToken = Meteor.isClient && Accounts._storedLoginToken();

// on initial load, prefer to use the token grabbed server-side if existing
let currentUserToken = cookieLoginToken || localStorageLoginToken;

// ...a login token has been passed to the config, however the "true" one is different ⚠️
// https://github.com/apollostack/meteor-integration/pull/57/files#r96745502
if (Meteor.isClient && cookieLoginToken && cookieLoginToken !== localStorageLoginToken) {
// be sure to pass the right token to the request!
currentUserToken = localStorageLoginToken;
}

if (!currentUserToken) {
next();
Expand Down Expand Up @@ -62,18 +94,7 @@ export const createMeteorNetworkInterface = (givenConfig) => {
}
return networkInterface;
};
// const configureSubscription = (wsClientProvided) => {
// const wsClient = wsClientProvided ? wsClientProvided : getDefaultWsClient();
// return {
// subscribe: (request, handler) => wsClient.subscribe({
// query: print(request.query),
// variables: request.variables,
// }, handler),
// unsubscribe: (id) => {
// wsClient.unsubscribe(id);
// },
// };
// }

export const meteorClientConfig = (networkInterfaceConfig) => {
const networkInterface = createMeteorNetworkInterface(networkInterfaceConfig);
let { initialState } = networkInterface;
Expand All @@ -86,12 +107,15 @@ export const meteorClientConfig = (networkInterfaceConfig) => {
return {
networkInterface,
initialState,
ssrMode: Meteor.isServer,

// Default to using Mongo _id, must use _id for queries.
dataIdFromObject: (result) => {
if (result._id && result.__typename) {
const dataId = result.__typename + result._id;
return dataId;
}

return null;
},
};
Expand Down
3 changes: 1 addition & 2 deletions main-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Accounts } from 'meteor/accounts-base';
import { _ } from 'meteor/underscore';
import { SubscriptionServer } from 'subscriptions-transport-ws';

export { meteorClientConfig, createMeteorNetworkInterface } from './main-client';
export { createMeteorNetworkInterface, meteorClientConfig } from './main-client';

const defaultConfig = {
path: '/graphql',
Expand Down Expand Up @@ -91,7 +91,6 @@ export const createApolloServer = (givenOptions = {}, givenConfig = {}) => {
}

return options;

}));

// Start GraphiQL if enabled
Expand Down
3 changes: 2 additions & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'apollo',
version: '0.2.1',
version: '0.3.1',
summary: ' 🚀 Add Apollo to your Meteor app',
git: 'https://github.com/apollostack/meteor-integration'
});
Expand All @@ -20,6 +20,7 @@ Package.onTest(function(api) {
api.use(['ecmascript',
'practicalmeteor:mocha',
'practicalmeteor:chai',
'http',
'apollo']);

api.mainModule('tests/client.js', 'client');
Expand Down
46 changes: 46 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "apollo-meteor-integration",
"version": "0.2.1",
"description": " 🚀 Add Apollo to your Meteor app",
"directories": {
"test": "tests"
},
"scripts": {
"test": "meteor test-packages ./ --driver-package practicalmeteor:mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/apollostack/meteor-integration.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/apollostack/meteor-integration/issues"
},
"homepage": "https://github.com/apollostack/meteor-integration#readme",
"dependencies": {
"apollo-client": "^0.8.4",
"babel": "^6.5.2",
"babel-core": "^6.22.1",
"babel-eslint": "^7.1.1",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.22.0",
"babel-preset-stage-2": "^6.22.0",
"body-parser": "^1.15.2",
"express": "^4.14.0",
"graphql": "^0.9.1",
"graphql-server-express": "^0.6.0",
"graphql-subscriptions": "^0.3.0",
"graphql-tools": "^0.10.0",
"subscriptions-transport-ws": "^0.5.1",
"whatwg-fetch": "^2.0.2"
},
"devDependencies": {
"eslint": "^3.15.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-import-resolver-meteor": "^0.3.4",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.9.0"
}
}
Loading

0 comments on commit 89f1c1d

Please sign in to comment.