This repository has been archived by the owner on Aug 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce apollo-fetch-polyfill package
Drop the global isomorphic-fetch polyfill from the main `apollo-fetch` package and provide a convenience package that simply re-exports `apollo-fetch` and includes the `isomorphic-fetch` polyfill.
- Loading branch information
Showing
15 changed files
with
246 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# apollo-fetch-polyfill change log | ||
|
||
## 1.0.0 | ||
|
||
- Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "apollo-fetch-polyfill", | ||
"version": "1.0.0", | ||
"description": "Wrapper around apollo-fetch which includes the isomorphic-fetch polyfill", | ||
"license": "MIT", | ||
"author": "Christoph Tavan <[email protected]>", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/apollographql/apollo-fetch/tree/master/packages/apollo-fetch-polyfill" | ||
}, | ||
"homepage": "https://github.com/apollographql/apollo-fetch#readme", | ||
"bugs": "https://github.com/apollographql/apollo-fetch/issues", | ||
"types": "./dist/main/index.d.ts", | ||
"main": "./dist/main/index.js", | ||
"module": "./dist/module/index.js", | ||
"files": ["src", "dist"], | ||
"scripts": { | ||
"prebuild:lib": "npm run clean:lib", | ||
"prebuild:test": "npm run clean:test", | ||
"pretest": "npm run lint && npm run build:test", | ||
"prepublishOnly": "npm run test && npm run build:lib", | ||
"clean:lib": "rimraf dist", | ||
"clean:test": "rimraf test/dist", | ||
"build:lib": "tsc -p tsconfig.main.json && tsc -p tsconfig.module.json", | ||
"build:test": "tsc -p tsconfig.test.json", | ||
"lint": "tslint --type-check -p tsconfig.main.json && tslint --type-check -p tsconfig.test.json", | ||
"test": "ava test/dist/test" | ||
}, | ||
"dependencies": { | ||
"apollo-fetch": "^0.5.2", | ||
"isomorphic-fetch": "^2.2.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "0.21.0", | ||
"rimraf": "2.6.1", | ||
"tslint": "5.6.0", | ||
"typescript": "2.4.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'isomorphic-fetch'; | ||
|
||
export * from 'apollo-fetch'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import test from 'ava'; | ||
import * as apolloFetch from 'apollo-fetch'; | ||
import * as apolloFetchPolyfill from '../../src/index.js'; | ||
|
||
test('exports the same things as apollo-fetch', t => { | ||
t.deepEqual(Object.keys(apolloFetchPolyfill), Object.keys(apolloFetch)); | ||
}); | ||
|
||
test('apollo-fetch-polyfill installs global fetch polyfill', t => { | ||
t.is(typeof fetch, 'function'); | ||
t.is(typeof Headers, 'function'); | ||
t.is(typeof Request, 'function'); | ||
t.is(typeof Response, 'function'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "dist/main", | ||
"target": "es5", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"removeComments": true, | ||
"noUnusedLocals": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["src/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "dist/module", | ||
"target": "es5", | ||
"module": "es6", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"removeComments": true, | ||
"noUnusedLocals": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["src/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "test/dist", | ||
"target": "es5", | ||
"noUnusedLocals": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["src/**/*.ts", "test/src/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
"rules": { | ||
"align": [false, "parameters", "arguments", "statements"], | ||
"ban": false, | ||
"class-name": true, | ||
"curly": true, | ||
"eofline": true, | ||
"forin": true, | ||
"indent": [true, "spaces", 2], | ||
"interface-name": false, | ||
"jsdoc-format": true, | ||
"label-position": true, | ||
"max-line-length": [true, 140], | ||
"member-access": true, | ||
"member-ordering": [ | ||
true, | ||
"public-before-private", | ||
"static-before-instance", | ||
"variables-before-functions" | ||
], | ||
"no-any": false, | ||
"no-arg": true, | ||
"no-bitwise": true, | ||
"no-conditional-assignment": true, | ||
"no-consecutive-blank-lines": false, | ||
"no-console": [true, "log", "debug", "info", "time", "timeEnd", "trace"], | ||
"no-construct": true, | ||
"no-debugger": true, | ||
"no-duplicate-variable": true, | ||
"no-empty": true, | ||
"no-eval": true, | ||
"no-inferrable-types": false, | ||
"no-internal-module": true, | ||
"no-null-keyword": false, | ||
"no-parameter-properties": false, | ||
"no-require-imports": false, | ||
"no-shadowed-variable": true, | ||
"no-switch-case-fall-through": true, | ||
"no-trailing-whitespace": true, | ||
"no-unused-expression": true, | ||
"no-use-before-declare": true, | ||
"no-var-keyword": true, | ||
"no-var-requires": true, | ||
"object-literal-sort-keys": false, | ||
"one-line": [ | ||
true, | ||
"check-open-brace", | ||
"check-catch", | ||
"check-else", | ||
"check-finally", | ||
"check-whitespace" | ||
], | ||
"quotemark": [true, "single", "avoid-escape"], | ||
"radix": true, | ||
"semicolon": [true, "always"], | ||
"switch-default": true, | ||
"trailing-comma": [ | ||
true, | ||
{ | ||
"multiline": "always", | ||
"singleline": "never" | ||
} | ||
], | ||
"triple-equals": [true, "allow-null-check"], | ||
"typedef": [ | ||
false, | ||
"call-signature", | ||
"parameter", | ||
"arrow-parameter", | ||
"property-declaration", | ||
"variable-declaration", | ||
"member-variable-declaration" | ||
], | ||
"typedef-whitespace": [ | ||
true, | ||
{ | ||
"call-signature": "nospace", | ||
"index-signature": "nospace", | ||
"parameter": "nospace", | ||
"property-declaration": "nospace", | ||
"variable-declaration": "nospace" | ||
}, | ||
{ | ||
"call-signature": "space", | ||
"index-signature": "space", | ||
"parameter": "space", | ||
"property-declaration": "space", | ||
"variable-declaration": "space" | ||
} | ||
], | ||
"variable-name": [ | ||
true, | ||
"check-format", | ||
"allow-pascal-case", | ||
"allow-leading-underscore", | ||
"ban-keywords" | ||
], | ||
"whitespace": [ | ||
true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-separator", | ||
"check-type" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as chai from 'chai'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
import { createApolloFetch } from '../src/apollo-fetch'; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
const { assert } = chai; | ||
|
||
describe('apollo-fetch', () => { | ||
describe('createApolloFetch', () => { | ||
it('should throw if fetch api is not present', () => { | ||
assert.throws(() => { | ||
createApolloFetch({ uri: 'test' }); | ||
}, /Global fetch API must be present or customFetch must be provided/); | ||
}); | ||
|
||
it('should not throw if fetch api is not present but customFetch is provided', () => { | ||
assert.doesNotThrow(() => { | ||
createApolloFetch({ | ||
uri: 'test', | ||
customFetch: () => | ||
new Promise((resolve, reject) => { | ||
resolve(new Response()); | ||
}), | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |