@amoutonbrady/graphql-client
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -5,3 +5,2 @@ // src/graphql-client.ts | ||
let headers = {}; | ||
const fetchFunc = options.fetch || fetch; | ||
const setHeaders = (newHeaders, override = false) => { | ||
@@ -12,7 +11,11 @@ headers = override ? newHeaders : { ...headers, ...newHeaders }; | ||
const request = (query, variables) => { | ||
return fetchFunc(url, { | ||
const finalHeaders = { "content-type": "application/json", ...headers }; | ||
if (authorization) { | ||
finalHeaders.authorization = authorization; | ||
} | ||
return fetch(url, { | ||
method: "POST", | ||
body: JSON.stringify({ query, variables }), | ||
headers: { authorization, "content-type": "application/json", ...headers } | ||
}).then((r) => r.json()).then(({ data, errors }) => { | ||
headers: finalHeaders | ||
}).then((response) => response.json()).then(({ data, errors }) => { | ||
if (errors) | ||
@@ -19,0 +22,0 @@ throw errors; |
@@ -1,4 +0,2 @@ | ||
import type nodeFetch from 'node-fetch'; | ||
interface Options { | ||
fetch?: typeof window.fetch | typeof nodeFetch; | ||
auth?: string; | ||
@@ -5,0 +3,0 @@ } |
{ | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"name": "@amoutonbrady/graphql-client", | ||
@@ -15,6 +15,11 @@ "description": "Minimalistic GraphQL client", | ||
}, | ||
"type": "module", | ||
"main": "dist/esm/graphql-client.js", | ||
"module": "dist/esm/graphql-client.js", | ||
"types": "dist/types/graphql-client.d.ts", | ||
"exports": "./dist/esm/graphql-client.js", | ||
"exports": { | ||
".": { | ||
"default": "./dist/esm/graphql-client.js" | ||
} | ||
}, | ||
"files": [ | ||
@@ -29,13 +34,13 @@ "dist" | ||
"devDependencies": { | ||
"@types/node-fetch": "^2.5.12", | ||
"c8": "^7.8.0", | ||
"esbuild": "^0.12.17", | ||
"jiti": "^1.11.0", | ||
"node-fetch": "^2.6.1", | ||
"esbuild": "^0.17.16", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.3.2", | ||
"typescript": "^4.3.5", | ||
"uvu": "^0.5.1" | ||
"prettier": "^2.8.7", | ||
"typescript": "^5.0.4", | ||
"vitest": "^0.30.0" | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=18.5", | ||
"pnpm": ">=8" | ||
}, | ||
"scripts": { | ||
@@ -46,6 +51,5 @@ "build:esm": "esbuild --bundle src/graphql-client.ts --outfile=dist/esm/graphql-client.js --target=esnext --platform=browser --format=esm", | ||
"format": "prettier --write \"{src,tests}/**/*.ts\"", | ||
"test": "pnpm build && uvu -r jiti/register tests", | ||
"test:coverage": "c8 --include=src npm test", | ||
"test:report": "c8 report --reporter=text-lcov > coverage.lcov" | ||
"test": "pnpm build && vitest run", | ||
"test:coverage": "vitest run --coverage" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
78
Yes
5195