Socket
Socket
Sign inDemoInstall

apollo-link-http-common

Package Overview
Dependencies
10
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.1

CHANGELOG.md

14

lib/bundle.umd.js

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

library = 'nodefetch';
throw new Error("fetch is not found globally and no fetcher passed, to fix pass a fetch for\n your environment like https://www.npmjs.com/package/" + library + ".\n\n For example:\n import fetch from '" + library + "';\n import { createHttpLink } from 'apollo-link-http';\n\n const link = createHttpLink({ uri: '/graphql', fetch: fetch });\n ");
throw new Error("\nfetch is not found globally and no fetcher passed, to fix pass a fetch for\nyour environment like https://www.npmjs.com/package/" + library + ".\n\nFor example:\nimport fetch from '" + library + "';\nimport { createHttpLink } from 'apollo-link-http';\n\nconst link = createHttpLink({ uri: '/graphql', fetch: fetch });");
}

@@ -107,13 +107,13 @@ };

};
var serializeFetchBody = function (body) {
var serializedBody;
var serializeFetchParameter = function (p, label) {
var serialized;
try {
serializedBody = JSON.stringify(body);
serialized = JSON.stringify(p);
}
catch (e) {
var parseError = new Error("Network request failed. Payload is not serializable: " + e.message);
var parseError = new Error("Network request failed. " + label + " is not serializable: " + e.message);
parseError.parseError = e;
throw parseError;
}
return serializedBody;
return serialized;
};

@@ -140,3 +140,3 @@ var selectURI = function (operation, fallbackURI) {

exports.selectHttpOptionsAndBody = selectHttpOptionsAndBody;
exports.serializeFetchBody = serializeFetchBody;
exports.serializeFetchParameter = serializeFetchParameter;
exports.selectURI = selectURI;

@@ -143,0 +143,0 @@

@@ -28,2 +28,8 @@ import { Operation } from 'apollo-link';

}
export interface Body {
query?: string;
operationName?: string;
variables?: Record<string, any>;
extensions?: Record<string, any>;
}
export interface HttpOptions {

@@ -56,8 +62,5 @@ uri?: string | UriFunction;

options: HttpConfig & Record<string, any>;
body: {
operationName: string;
variables: Record<string, any>;
};
body: Body;
};
export declare const serializeFetchBody: (body: any) => any;
export declare const serializeFetchParameter: (p: any, label: any) => any;
export declare const selectURI: (operation: any, fallbackURI?: string | ((Operation: any) => string)) => any;

@@ -67,3 +67,3 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {

library = 'nodefetch';
throw new Error("fetch is not found globally and no fetcher passed, to fix pass a fetch for\n your environment like https://www.npmjs.com/package/" + library + ".\n\n For example:\n import fetch from '" + library + "';\n import { createHttpLink } from 'apollo-link-http';\n\n const link = createHttpLink({ uri: '/graphql', fetch: fetch });\n ");
throw new Error("\nfetch is not found globally and no fetcher passed, to fix pass a fetch for\nyour environment like https://www.npmjs.com/package/" + library + ".\n\nFor example:\nimport fetch from '" + library + "';\nimport { createHttpLink } from 'apollo-link-http';\n\nconst link = createHttpLink({ uri: '/graphql', fetch: fetch });");
}

@@ -102,13 +102,13 @@ };

};
export var serializeFetchBody = function (body) {
var serializedBody;
export var serializeFetchParameter = function (p, label) {
var serialized;
try {
serializedBody = JSON.stringify(body);
serialized = JSON.stringify(p);
}
catch (e) {
var parseError = new Error("Network request failed. Payload is not serializable: " + e.message);
var parseError = new Error("Network request failed. " + label + " is not serializable: " + e.message);
parseError.parseError = e;
throw parseError;
}
return serializedBody;
return serialized;
};

@@ -115,0 +115,0 @@ export var selectURI = function (operation, fallbackURI) {

{
"name": "apollo-link-http-common",
"version": "0.1.0",
"description":
"Http utilities for Apollo Link shared across all links using http",
"version": "0.2.1",
"description": "Http utilities for Apollo Link shared across all links using http",
"main": "./lib/bundle.umd.js",

@@ -11,4 +10,3 @@ "module": "./lib/index.js",

"scripts": {
"build:browser":
"browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i apollo-link && npm run minify:browser",
"build:browser": "browserify ./lib/bundle.umd.js -o=./lib/bundle.js --i apollo-link && npm run minify:browser",
"build": "tsc -p .",

@@ -19,6 +17,4 @@ "bundle": "rollup -c",

"filesize": "npm run build && npm run build:browser",
"lint":
"tslint --type-check -p tsconfig.json -c ../../tslint.json src/*.ts",
"minify:browser":
"uglifyjs -c -m -o ./lib/bundle.min.js -- ./lib/bundle.js",
"lint": "tslint --type-check -p tsconfig.json -c ../../tslint.json src/*.ts",
"minify:browser": "uglifyjs -c -m -o ./lib/bundle.min.js -- ./lib/bundle.js",
"postbuild": "npm run bundle",

@@ -30,7 +26,11 @@ "prebuild": "npm run clean",

},
"keywords": ["apollo", "http", "network"],
"keywords": [
"apollo",
"http",
"network"
],
"author": "Evans Hauser",
"license": "MIT",
"dependencies": {
"apollo-link": "^1.1.0"
"apollo-link": "^1.2.0"
},

@@ -41,16 +41,16 @@ "peerDependencies": {

"devDependencies": {
"@types/graphql": "0.11.7",
"@types/graphql": "0.12.4",
"@types/jest": "21.1.10",
"browserify": "14.5.0",
"fetch-mock": "5.13.1",
"graphql": "0.12.3",
"graphql-tag": "2.6.1",
"graphql": "0.13.1",
"graphql-tag": "2.7.3",
"jest": "21.2.1",
"object-to-querystring": "1.0.4",
"object-to-querystring": "1.0.8",
"rimraf": "2.6.1",
"rollup": "0.53.3",
"rollup": "0.56.2",
"ts-jest": "21.2.4",
"tslint": "5.8.0",
"typescript": "2.6.2",
"uglify-js": "3.3.4"
"tslint": "5.9.1",
"typescript": "2.7.2",
"uglify-js": "3.3.11"
},

@@ -70,4 +70,10 @@ "repository": {

"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": ["ts", "tsx", "js", "json"]
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
],
"mapCoverage": true
}
}
import { createOperation, Observable, ApolloLink, execute } from 'apollo-link';
import gql from 'graphql-tag';
import * as fetchMock from 'fetch-mock';
import fetchMock from 'fetch-mock';

@@ -10,3 +10,3 @@ import {

selectURI,
serializeFetchBody,
serializeFetchParameter,
fallbackHttpConfig,

@@ -195,3 +195,3 @@ } from '../index';

describe('serializeFetchBody', () => {
describe('serializeFetchParameter', () => {
it('throws a parse error on an unparsable body', () => {

@@ -202,3 +202,3 @@ const b = {};

expect(() => serializeFetchBody(b)).toThrow();
expect(() => serializeFetchParameter(b, 'Label')).toThrow(/Label/);
});

@@ -209,3 +209,3 @@

expect(serializeFetchBody(body)).toEqual('{"no":"thing"}');
expect(serializeFetchParameter(body, 'Label')).toEqual('{"no":"thing"}');
});

@@ -215,4 +215,13 @@ });

describe('checkFetcher', () => {
let oldFetch;
beforeEach(() => {
oldFetch = window.fetch;
delete window.fetch;
});
afterEach(() => {
window.fetch = oldFetch;
});
it('throws if no fetch is present', () => {
if (typeof fetch !== 'undefined') fetch = undefined;
expect(() => checkFetcher(undefined)).toThrow(

@@ -224,3 +233,2 @@ /fetch is not found globally/,

it('does not throws if no fetch is present but a fetch is passed', () => {
if (typeof fetch !== 'undefined') fetch = undefined;
expect(() => checkFetcher(() => {})).not.toThrow();

@@ -227,0 +235,0 @@ });

@@ -47,2 +47,10 @@ import { Operation } from 'apollo-link';

// The body of a GraphQL-over-HTTP-POST request.
export interface Body {
query?: string;
operationName?: string;
variables?: Record<string, any>;
extensions?: Record<string, any>;
}
export interface HttpOptions {

@@ -168,13 +176,11 @@ /**

if (typeof window === 'undefined') library = 'nodefetch';
throw new Error(
`fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/${library}.
throw new Error(`
fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/${library}.
For example:
import fetch from '${library}';
import { createHttpLink } from 'apollo-link-http';
For example:
import fetch from '${library}';
import { createHttpLink } from 'apollo-link-http';
const link = createHttpLink({ uri: '/graphql', fetch: fetch });
`,
);
const link = createHttpLink({ uri: '/graphql', fetch: fetch });`);
}

@@ -227,3 +233,3 @@ };

const { operationName, extensions, variables, query } = operation;
const body = { operationName, variables };
const body: Body = { operationName, variables };

@@ -241,9 +247,9 @@ if (http.includeExtensions) (body as any).extensions = extensions;

export const serializeFetchBody = body => {
let serializedBody;
export const serializeFetchParameter = (p, label) => {
let serialized;
try {
serializedBody = JSON.stringify(body);
serialized = JSON.stringify(p);
} catch (e) {
const parseError = new Error(
`Network request failed. Payload is not serializable: ${e.message}`,
`Network request failed. ${label} is not serializable: ${e.message}`,
) as ClientParseError;

@@ -253,3 +259,3 @@ parseError.parseError = e;

}
return serializedBody;
return serialized;
};

@@ -256,0 +262,0 @@

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc