Skip to content

Commit 5f2124e

Browse files
dondonzacao
authored andcommitted
Add extensions to history
1 parent 8a4d2a3 commit 5f2124e

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

packages/graphiql-react/src/execution.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export function ExecutionContextProvider({
192192
history?.addToHistory({
193193
query,
194194
variables: variablesString,
195-
// dz todo when adding extensions to history
195+
extensions: extensionsString,
196196
headers: headersString,
197197
operationName: opName,
198198
});

packages/graphiql-react/src/history/context.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ export type HistoryContextType = {
88
/**
99
* Add an operation to the history.
1010
* @param operation The operation that was executed, consisting of the query,
11-
* variables, headers, and operation name.
11+
* variables, extensions, headers, and operation name.
1212
*/
1313
addToHistory(operation: {
1414
query?: string;
1515
variables?: string;
16+
extensions?: string;
1617
headers?: string;
1718
operationName?: string;
1819
}): void;
@@ -29,6 +30,7 @@ export type HistoryContextType = {
2930
args: {
3031
query?: string;
3132
variables?: string;
33+
extensions?: string;
3234
headers?: string;
3335
operationName?: string;
3436
label?: string;
@@ -50,6 +52,7 @@ export type HistoryContextType = {
5052
toggleFavorite(args: {
5153
query?: string;
5254
variables?: string;
55+
extensions?: string;
5356
headers?: string;
5457
operationName?: string;
5558
label?: string;
@@ -58,7 +61,7 @@ export type HistoryContextType = {
5861
/**
5962
* Delete an operation from the history.
6063
* @param args The operation that was executed, consisting of the query,
61-
* variables, headers, and operation name.
64+
* variables, extensions, headers, and operation name.
6265
* @param clearFavorites This is only if you press the 'clear' button
6366
*/
6467
deleteFromHistory(args: QueryStoreItem, clearFavorites?: boolean): void;

packages/graphiql-toolkit/src/storage/history.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class HistoryStore {
2828
private shouldSaveQuery(
2929
query?: string,
3030
variables?: string,
31+
extensions?: string,
3132
headers?: string,
3233
lastQuerySaved?: QueryStoreItem,
3334
) {
@@ -71,13 +72,15 @@ export class HistoryStore {
7172
updateHistory = ({
7273
query,
7374
variables,
75+
extensions,
7476
headers,
7577
operationName,
7678
}: QueryStoreItem) => {
7779
if (
7880
!this.shouldSaveQuery(
7981
query,
8082
variables,
83+
extensions,
8184
headers,
8285
this.history.fetchRecent(),
8386
)
@@ -87,6 +90,7 @@ export class HistoryStore {
8790
this.history.push({
8891
query,
8992
variables,
93+
extensions,
9094
headers,
9195
operationName,
9296
});
@@ -98,6 +102,7 @@ export class HistoryStore {
98102
toggleFavorite({
99103
query,
100104
variables,
105+
extensions,
101106
headers,
102107
operationName,
103108
label,
@@ -106,6 +111,7 @@ export class HistoryStore {
106111
const item: QueryStoreItem = {
107112
query,
108113
variables,
114+
extensions,
109115
headers,
110116
operationName,
111117
label,
@@ -126,6 +132,7 @@ export class HistoryStore {
126132
{
127133
query,
128134
variables,
135+
extensions,
129136
headers,
130137
operationName,
131138
label,
@@ -136,6 +143,7 @@ export class HistoryStore {
136143
const item = {
137144
query,
138145
variables,
146+
extensions,
139147
headers,
140148
operationName,
141149
label,
@@ -149,14 +157,15 @@ export class HistoryStore {
149157
}
150158

151159
deleteHistory = (
152-
{ query, variables, headers, operationName, favorite }: QueryStoreItem,
160+
{ query, variables, extensions, headers, operationName, favorite }: QueryStoreItem,
153161
clearFavorites = false,
154162
) => {
155163
function deleteFromStore(store: QueryStore) {
156164
const found = store.items.find(
157165
x =>
158166
x.query === query &&
159167
x.variables === variables &&
168+
x.extensions === extensions &&
160169
x.headers === headers &&
161170
x.operationName === operationName,
162171
);

packages/graphiql-toolkit/src/storage/query.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { StorageAPI } from './base';
33
export type QueryStoreItem = {
44
query?: string;
55
variables?: string;
6+
extensions?: string;
67
headers?: string;
78
operationName?: string;
89
label?: string;
@@ -29,6 +30,7 @@ export class QueryStore {
2930
x =>
3031
x.query === item.query &&
3132
x.variables === item.variables &&
33+
x.extensions === item.extensions &&
3234
x.headers === item.headers &&
3335
x.operationName === item.operationName,
3436
);
@@ -40,6 +42,7 @@ export class QueryStore {
4042
if (
4143
found.query === item.query &&
4244
found.variables === item.variables &&
45+
found.extensions === item.extensions &&
4346
found.headers === item.headers &&
4447
found.operationName === item.operationName
4548
) {
@@ -53,6 +56,7 @@ export class QueryStore {
5356
x =>
5457
x.query === item.query &&
5558
x.variables === item.variables &&
59+
x.extensions === item.extensions &&
5660
x.headers === item.headers &&
5761
x.operationName === item.operationName,
5862
);
@@ -67,6 +71,7 @@ export class QueryStore {
6771
x =>
6872
x.query === item.query &&
6973
x.variables === item.variables &&
74+
x.extensions === item.extensions &&
7075
x.headers === item.headers &&
7176
x.operationName === item.operationName,
7277
);

0 commit comments

Comments
 (0)