@kitql/client
Advanced tools
Comparing version 0.0.20 to 0.0.21
28
index.js
@@ -6,2 +6,3 @@ 'use strict'; | ||
const graphql = require('graphql'); | ||
const helper = require('@kitql/helper'); | ||
@@ -34,6 +35,9 @@ (function (RequestStatus) { | ||
this.headersContentType = options.headersContentType || 'application/graphql+json'; | ||
this.logLevel = options.logLevel || 'all'; | ||
this.log = new helper.Log('KitQL Client'); | ||
} | ||
async request({ skFetch, document, variables, cacheKey, cacheMs }) { | ||
async request({ skFetch, document, variables, cacheKey, cacheMs, browser }) { | ||
//Cache key... Relys on the order of the variables :s | ||
const key = JSON.stringify({ cacheKey, variables }); | ||
const needToLog = this.logLevel === 'all' || (this.logLevel === 'server' && !browser); | ||
// Check the cache | ||
@@ -44,5 +48,27 @@ if (cacheMs !== 0 && this.cache[key] !== undefined) { | ||
if (xMs < (cacheMs || this.cacheMs)) { | ||
if (needToLog) { | ||
this.log.info(`${helper.logCyan('Mode:')} ` + | ||
`${helper.logGreen(browser ? 'browser' : 'ssr')}, ` + | ||
`${helper.logCyan('From:')} ${helper.logGreen('CACHE')}, ` + | ||
`${helper.logCyan('Operation:')} ${helper.logGreen(cacheKey)}`); | ||
} | ||
return { ...this.cache[key], from: exports.RequestFrom.CACHE }; | ||
} | ||
} | ||
if (needToLog) { | ||
this.log.info(`${helper.logCyan('Mode:')} ` + | ||
`${helper.logGreen(browser ? 'browser' : 'ssr')}, ` + | ||
`${helper.logCyan('From:')} ${helper.logGreen('NETWORK')}, ` + | ||
`${helper.logCyan('Operation:')} ${helper.logGreen(cacheKey)}`); | ||
} | ||
// If | ||
// 1/ we are in SSR | ||
// 2/ we don't provide a fetch function | ||
// 3/ credentials is 'include' | ||
// => You are probably doing something wrong! | ||
if (!browser && !skFetch && this.credentials === 'include') { | ||
this.log.error(`I think that either:` + | ||
`\n\t\t1/ you forgot to provide \`fetch\`! As we are in SSR & include here. > ${cacheKey}({ fetch: ??? })` + | ||
`\n\t\t2/ you should run this in a browser only.`); | ||
} | ||
const fetchToUse = skFetch ? skFetch : fetch; | ||
@@ -49,0 +75,0 @@ let dateToReturn = { |
@@ -18,2 +18,3 @@ export declare type ClientSettings = { | ||
headersContentType?: 'application/graphql+json' | 'application/json'; | ||
logLevel: 'all' | 'server' | 'none'; | ||
}; | ||
@@ -64,5 +65,7 @@ export declare type RequestSettings = { | ||
private headersContentType; | ||
private logLevel; | ||
private cache; | ||
private log; | ||
constructor(options: ClientSettings); | ||
request<D, V>({ skFetch, document, variables, cacheKey, cacheMs }: { | ||
request<D, V>({ skFetch, document, variables, cacheKey, cacheMs, browser }: { | ||
skFetch: any; | ||
@@ -73,3 +76,4 @@ document: any; | ||
cacheMs: any; | ||
browser: any; | ||
}): Promise<ResponseResult<D, V>>; | ||
} |
{ | ||
"name": "@kitql/client", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"dependencies": { | ||
"graphql": "16.2.0" | ||
"@kitql/helper": "0.0.2", | ||
"graphql": "16.3.0" | ||
}, | ||
@@ -13,2 +14,5 @@ "repository": { | ||
"license": "MIT", | ||
"engines": { | ||
"node": "17.4.0" | ||
}, | ||
"main": "index.js", | ||
@@ -15,0 +19,0 @@ "module": "index.mjs", |
Sorry, the diff of this file is not supported yet
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
15414
409
2
+ Added@kitql/helper@0.0.2
+ Added@kitql/helper@0.0.2(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedargs@5.0.3(transitive)
+ Addedatomic-sleep@1.0.0(transitive)
+ Addedcamelcase@5.0.0(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcolorette@2.0.20(transitive)
+ Addeddateformat@4.6.3(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfast-redact@3.5.0(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedgraphql@16.3.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjoycon@3.1.1(transitive)
+ Addedleven@2.1.0(transitive)
+ Addedmri@1.1.4(transitive)
+ Addedon-exit-leak-free@0.2.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpino@7.6.5(transitive)
+ Addedpino-pretty@7.5.1(transitive)
+ Addedpino-std-serializers@4.0.0(transitive)
+ Addedprocess-warning@1.0.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedquick-format-unescaped@4.0.4(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedreal-require@0.1.0(transitive)
+ Addedrfdc@1.4.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafe-stable-stringify@2.5.0(transitive)
+ Addedsecure-json-parse@2.7.0(transitive)
+ Addedsonic-boom@2.8.0(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-json-comments@3.1.1(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedthread-stream@0.13.2(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedgraphql@16.2.0(transitive)
Updatedgraphql@16.3.0