@amoutonbrady/graphql-client
Advanced tools
Comparing version 0.2.2 to 0.3.0
// src/graphql-client.ts | ||
function GraphQLClient(url, options = { fetch: fetch.bind(window), auth: "" }) { | ||
let authorization = options.auth; | ||
let headers = {}; | ||
const setHeaders = (newHeaders, override = false) => { | ||
headers = override ? newHeaders : { ...headers, ...newHeaders }; | ||
}; | ||
const setAuth = (token) => authorization = token; | ||
@@ -9,3 +13,3 @@ const request = (query, variables) => { | ||
body: JSON.stringify({ query, variables }), | ||
headers: { authorization, "content-type": "application/json" } | ||
headers: { authorization, "content-type": "application/json", ...headers } | ||
}).then((r) => r.json()).then(({ data, errors }) => { | ||
@@ -19,3 +23,4 @@ if (errors) | ||
request, | ||
setAuth | ||
setAuth, | ||
setHeaders | ||
}; | ||
@@ -22,0 +27,0 @@ } |
@@ -24,2 +24,3 @@ import type nodeFetch from 'node-fetch'; | ||
setAuth: (token: string) => string; | ||
setHeaders: (newHeaders: Record<string, string>, override?: boolean) => void; | ||
}; | ||
@@ -26,0 +27,0 @@ /** |
{ | ||
"version": "0.2.2", | ||
"name": "@amoutonbrady/graphql-client", | ||
"description": "Minimalistic GraphQL client", | ||
"author": "Alexandre Mouton-Brady <amoutonbrady@gmail.com>", | ||
"private": false, | ||
"sideEffects": false, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/amoutonbrady/graphql-client.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"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", | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"graphql", | ||
"client", | ||
"minimal" | ||
], | ||
"devDependencies": { | ||
"@types/node-fetch": "^2.5.10", | ||
"c8": "^7.7.2", | ||
"esbuild": "^0.12.6", | ||
"jiti": "^1.10.1", | ||
"node-fetch": "^2.6.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.3.1", | ||
"typescript": "^4.3.2", | ||
"uvu": "^0.5.1" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"build:esm": "esbuild --bundle src/graphql-client.ts --outfile=dist/esm/graphql-client.js --target=esnext --platform=browser --format=esm", | ||
"build:types": "tsc", | ||
"build": "run-p build:*", | ||
"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" | ||
} | ||
} | ||
"version": "0.3.0", | ||
"name": "@amoutonbrady/graphql-client", | ||
"description": "Minimalistic GraphQL client", | ||
"author": "Alexandre Mouton-Brady <amoutonbrady@gmail.com>", | ||
"private": false, | ||
"sideEffects": false, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/amoutonbrady/graphql-client.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"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", | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"graphql", | ||
"client", | ||
"minimal" | ||
], | ||
"devDependencies": { | ||
"@types/node-fetch": "^2.5.12", | ||
"c8": "^7.8.0", | ||
"esbuild": "^0.12.17", | ||
"jiti": "^1.11.0", | ||
"node-fetch": "^2.6.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.3.2", | ||
"typescript": "^4.3.5", | ||
"uvu": "^0.5.1" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"build:esm": "esbuild --bundle src/graphql-client.ts --outfile=dist/esm/graphql-client.js --target=esnext --platform=browser --format=esm", | ||
"build:types": "tsc", | ||
"build": "run-p build:*", | ||
"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" | ||
} | ||
} |
@@ -11,3 +11,3 @@ <img alt="preview badge" src="https://img.shields.io/bundlephobia/min/@amoutonbrady/graphql-client"> | ||
- Fully tested: literally 3 functions | ||
- Minimal footprint: 30 loc, [~800 bytes minfied](https://bundlephobia.com/result?p=@amoutonbrady/graphql-client@0.0.2) | ||
- Minimal footprint: 30 loc, [~800 bytes minified](https://bundlephobia.com/result?p=@amoutonbrady/graphql-client@0.0.2) | ||
- No BS cache or w/e, ask data and you shall receive | ||
@@ -37,2 +37,5 @@ | ||
// You can set abitrary headers | ||
client.setHeaders({ Token: token }); | ||
// gql is just a pass through that minify the string for leaner payload | ||
@@ -39,0 +42,0 @@ const query = gql` |
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
76
57
5224
4