Skip to content

Commit

Permalink
Merge afc9531 into f2800a0
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Aug 12, 2017
2 parents f2800a0 + afc9531 commit d4613ad
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,4 +1,7 @@
build/
coverage/
node_modules/
npm/
npm-debug.log
package-lock.json
yarn.lock
2 changes: 2 additions & 0 deletions .npmignore
Expand Up @@ -2,8 +2,10 @@ build/tests/
src/
tests/
docs/
scripts/
.travis.yml
CHANGELOG.md
rollup.config.js
tsconfig.json
tsconfig.test.json
tslint.json
5 changes: 3 additions & 2 deletions .vscode/settings.json
Expand Up @@ -7,9 +7,10 @@
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"node_modules/**": true,
"node_modules": true,
"build": true,
"coverage": true
"coverage": true,
"npm": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}
6 changes: 5 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,10 @@
# Change log

### vNEXT
### v0.6.0-rc.1

- Fix the lift method (an issue since TypeScript 2.4) [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47)
- Update dependencies to latest [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47)
- Add a deploy script to keep compiled filed in the root directory [PR #48](https://github.com/kamilkisiela/apollo-client-rxjs/pull/48)

### v0.5.2

Expand Down
45 changes: 23 additions & 22 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "apollo-client-rxjs",
"version": "0.5.2",
"version": "0.6.0-rc.1",
"description": "Adds RxJS to ApolloClient",
"author": "Kamil Kisiela <kamil.kisiela@gmail.com>",
"license": "MIT",
Expand Down Expand Up @@ -29,7 +29,7 @@
"test-watch": "mocha --reporter spec --full-trace build/tests/index.js --watch",
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot --full-trace build/tests/index.js",
"postcoverage": "remap-istanbul --input coverage/coverage.json --type lcovonly --output coverage/lcov.info",
"lint": "tslint src/**/*.ts && tslint tests/*.ts",
"lint": "tslint src/**/*.ts && tslint tests/**/*.ts",
"prebuild": "npm run clean:build",
"build": "tsc",
"build-test": "tsc -p tsconfig.test.json",
Expand All @@ -39,32 +39,33 @@
"clean": "npm run clean:build && npm run clean:coverage",
"clean:build": "rimraf build/*",
"clean:coverage": "rimraf coverage/*",
"prepublish": "npm run clean && npm run build"
"prepare": "npm run clean && npm run build",
"deploy": "./scripts/deploy.sh"
},
"peerDependencies": {
"apollo-client": ">=0.7.2 <=0.10.1 || >=1.0.0-beta <2.0.0",
"rxjs": "^5.0.0-beta.12 || ^5.0.0-rc.1 || ^5.0.0"
"apollo-client": ">=1.0.0-beta <2.0.0",
"rxjs": "^5.0.0-beta.12 || >=5.0.0-rc.1 <6.0.0"
},
"devDependencies": {
"@types/chai": "^3.4.35",
"@types/mocha": "^2.2.40",
"@types/node": "^6.0.38",
"@types/sinon": "^1.16.35",
"apollo-client": "^1.0.0-rc.2",
"apollo-test-utils": "^0.2.0",
"chai": "^3.5.0",
"graphql": "^0.9.1",
"graphql-tag": "^1.3.1",
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/node": "^8.0.20",
"@types/sinon": "^2.3.3",
"apollo-client": "^1.9.1",
"apollo-test-utils": "^0.3.2",
"chai": "^4.1.1",
"graphql": "^0.10.5",
"graphql-tag": "^2.4.2",
"isomorphic-fetch": "^2.2.1",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"remap-istanbul": "^0.9.1",
"mocha": "^3.5.0",
"remap-istanbul": "^0.9.5",
"rimraf": "^2.6.1",
"rollup": "^0.41.5",
"rxjs": "^5.2.0",
"sinon": "^2.0.0",
"source-map-support": "^0.4.12",
"tslint": "^4.5.1",
"typescript": "^2.2.1"
"rollup": "^0.45.2",
"rxjs": "^5.4.2",
"sinon": "^3.2.0",
"source-map-support": "^0.4.15",
"tslint": "^5.6.0",
"typescript": "^2.4.2"
}
}
44 changes: 30 additions & 14 deletions rollup.config.js
@@ -1,23 +1,39 @@
const globals = {
'apollo-client': 'apollo',
'rxjs/Observable': 'Rx',
'rxjs/Observer': 'Rx',
'rxjs/Subscription': 'Rx',
'rxjs/Subscriber': 'Rx',
'rxjs/Operator': 'Rx',

'rxjs/symbol/observable': 'Rx.Symbol',

'rxjs/scheduler/AsyncScheduler': 'Rx.Scheduler.async',

'rxjs/observable/combineLatest': 'Rx.Observable',

'rxjs/operator/observeOn': 'Rx.Observable.prototype',
'rxjs/operator/switchMap': 'Rx.Observable.prototype'
}

export default {
entry: 'build/src/index.js',
dest: 'build/bundles/apollo-rxjs.umd.js',
format: 'umd',
sourceMap: true,
exports: 'named',
moduleName: 'apollo.rxjs',
globals: {
'apollo-client': 'apollo',
'rxjs/Observable': 'Rx',
'rxjs/Observer': 'Rx',
'rxjs/Subscription': 'Rx',
'rxjs/Subscriber': 'Rx',
'rxjs/Operator': 'Rx',

'rxjs/symbol/observable': 'Rx.Symbol',

'rxjs/scheduler/AsyncScheduler': 'Rx.Scheduler.async',
globals,
onwarn
}

'rxjs/observable/combineLatest': 'Rx.Observable',
function onwarn(message) {
const suppressed = [
'UNRESOLVED_IMPORT',
'THIS_IS_UNDEFINED'
];

'rxjs/operator/observeOn': 'Rx.Observable.prototype',
'rxjs/operator/switchMap': 'Rx.Observable.prototype'
if (!suppressed.find(code => message.code === code)) {
return console.warn(message.message);
}
}
46 changes: 46 additions & 0 deletions scripts/deploy.sh
@@ -0,0 +1,46 @@
#!/bin/sh -e


# When we publish to npm, the published files are available in the root
# directory, which allows for a clean include or require of sub-modules.
#
# var language = require('apollo-client-rxjs/rxify');
#

# Clear the built output
rm -rf ./build

# Compile new files
npm run build

# Make sure the ./npm directory is empty
rm -rf ./npm
mkdir ./npm

# Copy all files from ./lib/src to /npm
cd ./build/src && cp -r ./ ../../npm/
# Copy also the umd bundle with the source map file
cd ../bundles
cp apollo-rxjs.umd.js ../../npm/ && cp apollo-rxjs.umd.js.map ../../npm/

# Back to the root directory
cd ../../

# Ensure a vanilla package.json before deploying so other tools do not interpret
# The built output as requiring any further transformation.
node -e "var package = require('./package.json'); \
delete package.scripts; \
delete package.devDependencies; \
package.main = 'apollo-rxjs.umd.js'; \
package.module = 'index.js'; \
package.typings = 'index.d.ts'; \
var fs = require('fs'); \
fs.writeFileSync('./npm/package.json', JSON.stringify(package, null, 2)); \
"


# Copy few more files to ./npm
cp README.md npm/

echo 'deploying to npm...'
cd npm && npm publish && git push --tags
6 changes: 3 additions & 3 deletions src/RxObservableQuery.ts
Expand Up @@ -19,13 +19,13 @@ export class RxObservableQuery<T> extends Observable<ApolloQueryResult<T>> {
}
}

public lift<R>(operator: Operator<ApolloQueryResult<T>, ApolloQueryResult<R>>): Observable<ApolloQueryResult<R>> {
public lift<R>(operator: Operator<ApolloQueryResult<T>, R>): Observable<R> {
const observable = new RxObservableQuery<R>(this.apollo);

observable.source = this;
observable.operator = operator;
observable.operator = operator as any;

return observable;
return observable as any;
}

// apollo-specific methods
Expand Down
2 changes: 1 addition & 1 deletion src/utils/variables.ts
Expand Up @@ -46,7 +46,7 @@ export function observeVariables(variables?: Object): Observable<Object> {
observer.next(resultVariables);
});
});
};
}

function mapVariablesToObservables(variables?: Object): Observable<any>[] {
return Object.keys(variables)
Expand Down
8 changes: 4 additions & 4 deletions tests/RxApolloClient/watchQuery.ts
Expand Up @@ -12,7 +12,7 @@ describe('RxApolloClient.watchQuery', () => {

it('should get the result', (done) => {
const obs = client.watchQuery({
query: heroes.query
query: heroes.query,
});

obs.subscribe({
Expand All @@ -22,13 +22,13 @@ describe('RxApolloClient.watchQuery', () => {
},
error() {
done(new Error('should not be called'));
}
},
});
});

it('should be able to refetch', (done) => {
const obs = client.watchQuery({
query: heroes.query
query: heroes.query,
});

obs.subscribe({
Expand All @@ -37,7 +37,7 @@ describe('RxApolloClient.watchQuery', () => {
},
error() {
done(new Error('should not be called'));
}
},
});

obs.refetch(heroes.variables).then(({data}) => {
Expand Down
39 changes: 31 additions & 8 deletions tests/RxObservableQuery.ts
@@ -1,13 +1,14 @@
import { assert } from 'chai';
import { spy, stub } from 'sinon';
import { ApolloClient, ObservableQuery } from 'apollo-client';
import { ApolloClient, ObservableQuery, ApolloQueryResult } from 'apollo-client';

import * as heroes from './fixtures/heroes';
import { RxObservableQuery } from '../src/RxObservableQuery';
import { ObservableQueryRef } from '../src/utils/ObservableQueryRef';

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/filter';

describe('RxObservableQuery', () => {
let obsQuery: ObservableQuery<heroes.AllHeroesQueryResult>;
Expand Down Expand Up @@ -56,7 +57,9 @@ describe('RxObservableQuery', () => {
});

it('should be able to use a operator', (done: MochaDone) => {
rxObsQuery.map(result => result.data).subscribe({
rxObsQuery
.map(result => result.data)
.subscribe({
next(result) {
assert.deepEqual(result, heroes.data);
done();
Expand All @@ -67,6 +70,26 @@ describe('RxObservableQuery', () => {
});
});

it('should be able to use multiple operators', (done: MochaDone) => {
function onlyFoo(hero: heroes.Hero): boolean {
return !!hero.name.match(/foo/i);
}

rxObsQuery
.map<ApolloQueryResult<heroes.AllHeroesQueryResult>, heroes.Hero[]>
(result => result.data.allHeroes.heroes)
.map(heroes => heroes.filter(onlyFoo))
.subscribe({
next(result) {
assert.deepEqual(result, heroes.data.allHeroes.heroes.filter(onlyFoo));
done();
},
error() {
done(new Error('should not be called'));
},
});
});

it('should be chainable', (done: MochaDone) => {
const counter = { calls: 0 };

Expand Down Expand Up @@ -97,7 +120,7 @@ describe('RxObservableQuery', () => {
const promise = rxObsQuery.refetch(heroes.variables);

assert.deepEqual(stubbed.args[0], [heroes.variables]);
assert.equal(promise, 'promise');
assert.equal(promise, 'promise' as any);
});

it('should be able to startPolling', () => {
Expand All @@ -121,7 +144,7 @@ describe('RxObservableQuery', () => {
const promise = rxObsQuery.fetchMore(options);

assert.deepEqual(stubbed.args[0], [options]);
assert.equal(promise, 'promise');
assert.equal(promise, 'promise' as any);
});

it('should be able to subscribeToMore', () => {
Expand All @@ -130,7 +153,7 @@ describe('RxObservableQuery', () => {
const fn = rxObsQuery.subscribeToMore(options);

assert.deepEqual(stubbed.args[0], [options]);
assert.equal(fn, 'fn');
assert.equal(fn, 'fn' as any);
});

it('should be able to updateQuery', () => {
Expand All @@ -148,7 +171,7 @@ describe('RxObservableQuery', () => {
stub(obsQuery, 'result').returns('promise');
const promise = rxObsQuery.result();

assert.equal(promise, 'promise');
assert.equal(promise, 'promise' as any);
});

it('should be able to use currentResult', () => {
Expand All @@ -168,7 +191,7 @@ describe('RxObservableQuery', () => {
const promise = rxObsQuery.setOptions(options);

assert.deepEqual(stubbed.args[0], [options]);
assert.equal(promise, 'promise');
assert.equal(promise, 'promise' as any);
});

it('should be able to setVariables', () => {
Expand All @@ -177,7 +200,7 @@ describe('RxObservableQuery', () => {
const promise = rxObsQuery.setVariables(variables);

assert.deepEqual(stubbed.args[0], [variables, false]);
assert.equal(promise, 'promise');
assert.equal(promise, 'promise' as any);
});
});
});

0 comments on commit d4613ad

Please sign in to comment.