@amoutonbrady/graphql-client
Advanced tools
Comparing version 0.0.4 to 0.1.0
// src/graphql-client.ts | ||
function GraphQLClient(url, auth = "") { | ||
let authorization = auth; | ||
function GraphQLClient(url, options) { | ||
let authorization = options.auth || ""; | ||
const setAuth = (token) => authorization = token; | ||
const request = (query, variables) => { | ||
return fetch(url, { | ||
return options.fetch(url, { | ||
method: "POST", | ||
@@ -8,0 +8,0 @@ body: JSON.stringify({query, variables}), |
@@ -16,7 +16,7 @@ var __defineProperty = Object.defineProperty; | ||
}); | ||
function GraphQLClient(url, auth = "") { | ||
let authorization = auth; | ||
function GraphQLClient(url, options) { | ||
let authorization = options.auth || ""; | ||
const setAuth = (token) => authorization = token; | ||
const request = (query, variables) => { | ||
return fetch(url, { | ||
return options.fetch(url, { | ||
method: "POST", | ||
@@ -23,0 +23,0 @@ body: JSON.stringify({query, variables}), |
@@ -1,1 +0,1 @@ | ||
var GraphClient=(()=>{var s=Object.defineProperty,g=(e,t)=>()=>(t||(t={exports:{}},e(t.exports,t)),t.exports),q=e=>s(e,"__esModule",{value:!0}),y=(e,t)=>{q(e);for(var r in t)s(e,r,{get:t[r],enumerable:!0})};var l=g(m=>{y(m,{GraphQLClient:()=>i,gql:()=>h});function i(e,t=""){let r=t;const u=a=>r=a,p=(a,c)=>fetch(e,{method:"POST",body:JSON.stringify({query:a,variables:c}),headers:{authorization:r,"content-type":"application/json"}}).then(n=>n.json()).then(({data:n,errors:o})=>{if(o)throw o;return n});return{request:p,setAuth:u}}const h=e=>e.join(" ").replace(/#.+\r?\n|\r/g,"").replace(/\r?\n|\r/g,"").replace(/\s{2,}/g," ").trim()});return l();})(); | ||
var GraphClient=(()=>{var i=Object.defineProperty,g=(t,e)=>()=>(e||(e={exports:{}},t(e.exports,e)),e.exports),q=t=>i(t,"__esModule",{value:!0}),y=(t,e)=>{q(t);for(var r in e)i(t,r,{get:e[r],enumerable:!0})};var l=g(m=>{y(m,{GraphQLClient:()=>s,gql:()=>h});function s(t,e){let r=e.auth||"";const c=n=>r=n,p=(n,u)=>e.fetch(t,{method:"POST",body:JSON.stringify({query:n,variables:u}),headers:{authorization:r,"content-type":"application/json"}}).then(a=>a.json()).then(({data:a,errors:o})=>{if(o)throw o;return a});return{request:p,setAuth:c}}const h=t=>t.join(" ").replace(/#.+\r?\n|\r/g,"").replace(/\r?\n|\r/g,"").replace(/\s{2,}/g," ").trim()});return l();})(); |
{ | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"name": "@amoutonbrady/graphql-client", | ||
@@ -8,2 +8,6 @@ "description": "Minimalistic GraphQL client", | ||
"sideEffects": false, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/amoutonbrady/graphql-client.git" | ||
}, | ||
"publishConfig": { | ||
@@ -16,2 +20,9 @@ "access": "public" | ||
"types": "types/graphql-client.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/graphql-client.esm.js", | ||
"browser": "./dist/graphql-client.min.js", | ||
"require": "./dist/graphql-client.js" | ||
} | ||
}, | ||
"files": [ | ||
@@ -41,12 +52,12 @@ "dist", | ||
"@types/node-fetch": "^2.5.7", | ||
"c8": "^7.3.0", | ||
"esbuild": "^0.6.27", | ||
"node-fetch": "^2.6.0", | ||
"c8": "^7.3.4", | ||
"esbuild": "^0.6.34", | ||
"node-fetch": "^2.6.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.1.0", | ||
"prettier": "^2.1.2", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.0.2", | ||
"uvu": "^0.3.3" | ||
"typescript": "^4.0.3", | ||
"uvu": "^0.3.4" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -28,2 +28,5 @@ <img alt="preview badge" src="https://img.shields.io/bundlephobia/min/@amoutonbrady/graphql-client"> | ||
const client = GraphQLClient('https://jurassic.park/graphql'); | ||
// You can also provide your own fetch if you want to | ||
// const client = GraphQLClient('https://jurassic.park/graphql', { fetch: require('node-fetch') }); | ||
const token = getToken(); | ||
@@ -30,0 +33,0 @@ |
@@ -0,1 +1,6 @@ | ||
import type nodeFetch from 'node-fetch'; | ||
interface Options { | ||
fetch?: typeof window.fetch | typeof nodeFetch; | ||
auth?: string; | ||
} | ||
/** | ||
@@ -6,3 +11,3 @@ * Create a new GraphQL client that hold the URL of the instance | ||
* @param {string} url - Url of the graphql endpoint | ||
* @param {string} [auth=""] - Optional authorization header | ||
* @param {Options} options - Optional authorization header & fetch instance | ||
* | ||
@@ -17,3 +22,3 @@ * @example | ||
*/ | ||
export declare function GraphQLClient(url: string, auth?: string): { | ||
export declare function GraphQLClient(url: string, options?: Options): { | ||
request: <T = any>(query: string, variables?: Record<string, any>) => Promise<T>; | ||
@@ -42,1 +47,2 @@ setAuth: (token: string) => string; | ||
export declare const gql: (query: TemplateStringsArray) => string; | ||
export {}; |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
8487
7
107
54
0
0