Skip to content

Commit 2f16b7d

Browse files
committed
disable caching by default
1 parent 419ba9d commit 2f16b7d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/BatchedGraphQLClient.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@ import { Options, Variables } from './types'
22
import 'cross-fetch/polyfill'
33
import * as DataLoader from 'dataloader'
44
import { ClientError } from './ClientError'
5+
import { ClientOptions } from '.'
56

67
export class BatchedGraphQLClient {
78
public uri: string
89
public options: Options
910
private dataloader: DataLoader<string, any>
1011

11-
constructor(uri: string, options?: Options) {
12+
constructor(uri: string, options?: Options & ClientOptions) {
1213
this.uri = uri
14+
15+
const cache =
16+
options && typeof options.cacheResults !== 'undefined'
17+
? options.cacheResults
18+
: false
19+
20+
if (options && typeof options.cacheResults !== 'undefined') {
21+
delete options.cacheResults
22+
}
23+
1324
this.options = options || {}
14-
this.dataloader = new DataLoader(this.load, { cache: false })
25+
this.dataloader = new DataLoader(this.load, { cache })
1526
}
1627

1728
async request<T extends any>(

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ export interface GraphQLRequestContext {
3333
query: string
3434
variables?: Variables
3535
}
36+
37+
export interface ClientOptions {
38+
cacheResults?: boolean
39+
}

0 commit comments

Comments
 (0)