Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-link

Package Overview
Dependencies
Maintainers
3
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link - npm Package Compare versions

Comparing version 0.8.0 to 1.0.0

6

CHANGELOG.md
# Change log
### vNEXT
- added support for a `fromPromise` to make it easy to create an observable from a promise fetcher
# 0.8.0
- added support for `extensions` on an operation
# 0.7.0
- new operation API and start of changelog

4

lib/bundle.umd.js

@@ -55,3 +55,3 @@ (function (global, factory) {

}
function makePromise(observable) {
function toPromise(observable) {
var completed = false;

@@ -73,2 +73,4 @@ return new Promise(function (resolve, reject) {

}
var makePromise = toPromise;
function transformOperation(operation) {

@@ -75,0 +77,0 @@ var transformedOperation = {

@@ -11,5 +11,7 @@ /// <reference types="zen-observable" />

export declare function isTerminating(link: ApolloLink): boolean;
export declare function makePromise<R>(observable: Observable<R>): Promise<R>;
export declare function toPromise<R>(observable: Observable<R>): Promise<R>;
export declare const makePromise: typeof toPromise;
export declare function fromPromise<T>(promise: Promise<T>): Observable<T>;
export declare function transformOperation(operation: GraphQLRequest): GraphQLRequest;
export declare function createOperation(starting: any, operation: GraphQLRequest): Operation;
export declare function getKey(operation: GraphQLRequest): string;

@@ -20,2 +20,3 @@ var __extends = (this && this.__extends) || (function () {

import { getOperationName } from 'apollo-utilities';
import * as Observable from 'zen-observable';
import { print } from 'graphql/language/printer';

@@ -53,3 +54,3 @@ export function validateOperation(operation) {

}
export function makePromise(observable) {
export function toPromise(observable) {
var completed = false;

@@ -71,2 +72,13 @@ return new Promise(function (resolve, reject) {

}
export var makePromise = toPromise;
export function fromPromise(promise) {
return new Observable(function (observer) {
promise
.then(function (value) {
observer.next(value);
observer.complete();
})
.catch(observer.error.bind(observer));
});
}
export function transformOperation(operation) {

@@ -73,0 +85,0 @@ var transformedOperation = {

{
"name": "apollo-link",
"version": "0.8.0",
"version": "1.0.0",
"description": "Flexible, lightweight transport layer for GraphQL",

@@ -51,14 +51,14 @@ "author": "Evans Hauser <evanshauser@gmail.com>",

"@types/graphql": "0.11.5",
"@types/jest": "21.1.2",
"@types/zen-observable": "^0.5.3",
"browserify": "14.4.0",
"graphql": "^0.11.3",
"graphql-tag": "2.4.2",
"@types/jest": "21.1.4",
"@types/zen-observable": "0.5.3",
"browserify": "14.5.0",
"graphql": "0.11.7",
"graphql-tag": "2.5.0",
"jest": "21.2.1",
"rimraf": "2.6.1",
"rollup": "0.45.2",
"ts-jest": "21.1.2",
"tslint": "5.7.0",
"ts-jest": "21.1.3",
"tslint": "5.8.0",
"typescript": "2.5.1",
"uglify-js": "3.1.3"
"uglify-js": "3.1.5"
},

@@ -65,0 +65,0 @@ "jest": {

@@ -1,2 +0,2 @@

import * as LinkUtils from '../linkUtils';
import { validateOperation, fromPromise, makePromise } from '../linkUtils';
import * as Observable from 'zen-observable';

@@ -7,7 +7,3 @@

it('should throw when invalid field in operation', () => {
expect(() =>
LinkUtils.validateOperation(<any>{
qwerty: '',
}),
).toThrow();
expect(() => validateOperation(<any>{ qwerty: '' })).toThrow();
});

@@ -17,3 +13,3 @@

expect(() =>
LinkUtils.validateOperation(<any>{
validateOperation(<any>{
query: '',

@@ -26,3 +22,3 @@ }),

expect(() =>
LinkUtils.validateOperation({
validateOperation({
query: '1234',

@@ -45,3 +41,3 @@ context: {},

it('return next call as Promise resolution', () => {
return LinkUtils.makePromise(Observable.of(data)).then(result =>
return makePromise(Observable.of(data)).then(result =>
expect(data).toEqual(result),

@@ -52,5 +48,3 @@ );

it('return error call as Promise rejection', () => {
return LinkUtils.makePromise(
new Observable(observer => observer.error(error)),
)
return makePromise(new Observable(observer => observer.error(error)))
.then(expect.fail)

@@ -74,3 +68,3 @@ .catch(actualError => expect(error).toEqual(actualError));

it('return error call as Promise rejection', done => {
LinkUtils.makePromise(Observable.of(data, data)).then(result => {
makePromise(Observable.of(data, data)).then(result => {
expect(data).toEqual(result);

@@ -83,2 +77,24 @@ expect(spy).toHaveBeenCalled();

});
describe('fromPromise', () => {
const data = {
data: {
hello: 'world',
},
};
const error = new Error('I always error');
it('return next call as Promise resolution', () => {
const observable = fromPromise(Promise.resolve(data));
return makePromise(observable).then(result =>
expect(data).toEqual(result),
);
});
it('return Promise rejection as error call', () => {
const observable = fromPromise(Promise.reject(error));
return makePromise(observable)
.then(expect.fail)
.catch(actualError => expect(error).toEqual(actualError));
});
});
});

@@ -38,3 +38,3 @@ import { getOperationName } from 'apollo-utilities';

export function makePromise<R>(observable: Observable<R>): Promise<R> {
export function toPromise<R>(observable: Observable<R>): Promise<R> {
let completed = false;

@@ -58,2 +58,16 @@ return new Promise<R>((resolve, reject) => {

// backwards compat
export const makePromise = toPromise;
export function fromPromise<T>(promise: Promise<T>): Observable<T> {
return new Observable<T>(observer => {
promise
.then((value: T) => {
observer.next(value);
observer.complete();
})
.catch(observer.error.bind(observer));
});
}
export function transformOperation(operation: GraphQLRequest): GraphQLRequest {

@@ -60,0 +74,0 @@ const transformedOperation: GraphQLRequest = {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc