@quesmed/types 2.2.96 → 2.2.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/resolvers/mutation/restricted/todo.d.ts +3 -2
- package/dist/cjs/resolvers/mutation/restricted/todo.js +84 -30
- package/dist/cjs/resolvers/mutation/sample.d.ts +2 -1
- package/dist/cjs/resolvers/mutation/sample.js +19 -1
- package/dist/mjs/resolvers/mutation/restricted/todo.d.ts +3 -2
- package/dist/mjs/resolvers/mutation/restricted/todo.js +81 -28
- package/dist/mjs/resolvers/mutation/sample.d.ts +2 -1
- package/dist/mjs/resolvers/mutation/sample.js +17 -0
- package/package.json +1 -1
|
@@ -25,6 +25,7 @@ export interface ISaveTodosVar {
|
|
|
25
25
|
}
|
|
26
26
|
export declare type ISaveTodosData = RestrictedData<(graphqlNormalize & ITodo)[], 'saveTodos'>;
|
|
27
27
|
export declare function saveTodosCache(cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<ISaveTodosData>, options: ApolloUpdateOptions): void;
|
|
28
|
+
export declare const optimisticSaveTodos: (todo: ITodo, cardIndex: number, todoInput: ITodoInput) => ISaveTodosData;
|
|
28
29
|
export declare const ADD_TO_DAILY_STACK: import("@apollo/client").DocumentNode;
|
|
29
30
|
export interface IAddToDailyStackVar {
|
|
30
31
|
conceptIds: Id[];
|
|
@@ -37,8 +38,8 @@ export interface IRemoveFromDailyStackVar {
|
|
|
37
38
|
conceptId?: Id;
|
|
38
39
|
}
|
|
39
40
|
export declare type IRemoveFromDailyStackData = RestrictedData<(graphqlNormalize & IUserCompletedCard)[], 'removeFromDailyStack'>;
|
|
40
|
-
export declare const
|
|
41
|
-
export declare const
|
|
41
|
+
export declare const updateCacheOnRemoveFromDailyStack: (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IRemoveFromDailyStackData>, options: ApolloUpdateOptions) => void;
|
|
42
|
+
export declare const updateCacheOnAddToDailyStack: (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IAddToDailyStackData>) => void;
|
|
42
43
|
export declare const REFRESH_DAILY_TASK: import("@apollo/client").DocumentNode;
|
|
43
44
|
export declare type IRefreshDailyTaskVar = null;
|
|
44
45
|
export declare type IRefreshDailyTaskData = RestrictedData<graphqlNormalize & ITodo, 'refreshDailyTask'>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REFRESH_DAILY_TASK = exports.
|
|
3
|
+
exports.REFRESH_DAILY_TASK = exports.updateCacheOnAddToDailyStack = exports.updateCacheOnRemoveFromDailyStack = exports.REMOVE_FROM_DAILY_STACK = exports.ADD_TO_DAILY_STACK = exports.optimisticSaveTodos = exports.saveTodosCache = exports.SAVE_TODO = exports.BUILD_TODO = void 0;
|
|
4
4
|
const client_1 = require("@apollo/client");
|
|
5
5
|
const fragments_1 = require("../../fragments");
|
|
6
|
+
const restricted_1 = require("../../query/restricted");
|
|
6
7
|
exports.BUILD_TODO = (0, client_1.gql) `
|
|
7
8
|
mutation BuildTodo($buildTodo: BuildTodoInput!) {
|
|
8
9
|
restricted {
|
|
@@ -78,6 +79,23 @@ function saveTodosCache(cache, result, options) {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
exports.saveTodosCache = saveTodosCache;
|
|
82
|
+
const optimisticSaveTodos = (todo, cardIndex, todoInput) => {
|
|
83
|
+
const { score, timeTaken } = todoInput;
|
|
84
|
+
const { marks } = todo;
|
|
85
|
+
const newMarks = [...marks];
|
|
86
|
+
newMarks[cardIndex] = { ...marks[cardIndex], score, timeTaken };
|
|
87
|
+
return {
|
|
88
|
+
restricted: {
|
|
89
|
+
saveTodos: [
|
|
90
|
+
{
|
|
91
|
+
...todo,
|
|
92
|
+
marks: newMarks,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
exports.optimisticSaveTodos = optimisticSaveTodos;
|
|
81
99
|
exports.ADD_TO_DAILY_STACK = (0, client_1.gql) `
|
|
82
100
|
${fragments_1.PICTURE_FIELDS}
|
|
83
101
|
mutation AddToDailyStack($conceptIds: [Int!]!) {
|
|
@@ -135,49 +153,85 @@ exports.REMOVE_FROM_DAILY_STACK = (0, client_1.gql) `
|
|
|
135
153
|
}
|
|
136
154
|
}
|
|
137
155
|
`;
|
|
138
|
-
const
|
|
156
|
+
const updateCacheOnRemoveFromDailyStack = (cache, result, options) => {
|
|
139
157
|
const { removeFromDailyStack } = result.data?.restricted || {};
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
158
|
+
const { variables } = options || {};
|
|
159
|
+
const { todoId } = variables || {};
|
|
160
|
+
if (!removeFromDailyStack || !removeFromDailyStack.length) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const toRemove = new Set(removeFromDailyStack.map(({ cardId }) => cardId));
|
|
164
|
+
const prevData = cache.readQuery({
|
|
165
|
+
query: restricted_1.USER_COMPLETED_DATA,
|
|
143
166
|
});
|
|
144
|
-
if (prevData
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
const newCompletedCards = prevData.completedCards.filter(({ id }) => !toRemove.has(id));
|
|
150
|
-
cache.writeFragment({
|
|
151
|
-
id: cache.identify({ id: userId, __typename: 'User' }),
|
|
167
|
+
if (prevData) {
|
|
168
|
+
const newCompletedCards = prevData.restricted.user.completedCards.filter(({ cardId }) => !toRemove.has(cardId));
|
|
169
|
+
cache.writeQuery({
|
|
170
|
+
query: restricted_1.USER_COMPLETED_DATA,
|
|
152
171
|
data: {
|
|
153
|
-
|
|
154
|
-
|
|
172
|
+
...prevData,
|
|
173
|
+
restricted: {
|
|
174
|
+
...prevData.restricted,
|
|
175
|
+
user: {
|
|
176
|
+
...prevData.restricted.user,
|
|
177
|
+
completedCards: newCompletedCards,
|
|
178
|
+
completedCardsCount: newCompletedCards.length,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
155
181
|
},
|
|
156
|
-
fragment: fragments_1.COMPLETED_CARDS,
|
|
157
182
|
});
|
|
158
183
|
}
|
|
184
|
+
if (todoId) {
|
|
185
|
+
const prevData = cache.readQuery({
|
|
186
|
+
variables: { id: todoId },
|
|
187
|
+
query: restricted_1.TODO,
|
|
188
|
+
});
|
|
189
|
+
if (prevData) {
|
|
190
|
+
const { marks } = prevData.restricted.todo;
|
|
191
|
+
cache.writeQuery({
|
|
192
|
+
query: restricted_1.TODO,
|
|
193
|
+
data: {
|
|
194
|
+
...prevData,
|
|
195
|
+
restricted: {
|
|
196
|
+
...prevData.restricted,
|
|
197
|
+
todo: {
|
|
198
|
+
...prevData.restricted.todo,
|
|
199
|
+
marks: marks.filter(({ cardId }) => !toRemove.has(Number(cardId))),
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
159
206
|
};
|
|
160
|
-
exports.
|
|
161
|
-
const
|
|
207
|
+
exports.updateCacheOnRemoveFromDailyStack = updateCacheOnRemoveFromDailyStack;
|
|
208
|
+
const updateCacheOnAddToDailyStack = (cache, result) => {
|
|
162
209
|
const { addToDailyStack } = result.data?.restricted || {};
|
|
163
|
-
const prevData = cache.
|
|
164
|
-
|
|
165
|
-
fragment: fragments_1.COMPLETED_CARDS,
|
|
210
|
+
const prevData = cache.readQuery({
|
|
211
|
+
query: restricted_1.USER_COMPLETED_DATA,
|
|
166
212
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
213
|
+
if (prevData && addToDailyStack) {
|
|
214
|
+
const newCompletedCards = [
|
|
215
|
+
...prevData.restricted.user.completedCards,
|
|
216
|
+
...addToDailyStack,
|
|
217
|
+
];
|
|
218
|
+
cache.writeQuery({
|
|
219
|
+
query: restricted_1.USER_COMPLETED_DATA,
|
|
172
220
|
data: {
|
|
173
|
-
|
|
174
|
-
|
|
221
|
+
...prevData,
|
|
222
|
+
restricted: {
|
|
223
|
+
...prevData.restricted,
|
|
224
|
+
user: {
|
|
225
|
+
...prevData.restricted.user,
|
|
226
|
+
completedCards: newCompletedCards,
|
|
227
|
+
completedCardsCount: newCompletedCards.length,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
175
230
|
},
|
|
176
|
-
fragment: fragments_1.COMPLETED_CARDS,
|
|
177
231
|
});
|
|
178
232
|
}
|
|
179
233
|
};
|
|
180
|
-
exports.
|
|
234
|
+
exports.updateCacheOnAddToDailyStack = updateCacheOnAddToDailyStack;
|
|
181
235
|
exports.REFRESH_DAILY_TASK = (0, client_1.gql) `
|
|
182
236
|
${fragments_1.PICTURE_FIELDS}
|
|
183
237
|
mutation RefreshDailyTask {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ApolloClient } from '@apollo/client';
|
|
2
|
-
import { IMarksheetInput } from './restricted';
|
|
2
|
+
import { IMarksheetInput, ITodoInput } from './restricted';
|
|
3
3
|
export declare const saveSampleMarksheets: (client: ApolloClient<any>, marksheetInput: IMarksheetInput, questionIndex: number) => void;
|
|
4
|
+
export declare const saveSampleTodoMark: (client: ApolloClient<any>, todoInput: ITodoInput, markId: number) => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.saveSampleMarksheets = void 0;
|
|
3
|
+
exports.saveSampleTodoMark = exports.saveSampleMarksheets = void 0;
|
|
4
|
+
const client_1 = require("@apollo/client");
|
|
4
5
|
const query_1 = require("../query");
|
|
5
6
|
const saveSampleMarksheets = (client, marksheetInput, questionIndex) => {
|
|
6
7
|
const { timeTaken, choiceId, mark, marksheetId } = marksheetInput;
|
|
@@ -35,3 +36,20 @@ const saveSampleMarksheets = (client, marksheetInput, questionIndex) => {
|
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
exports.saveSampleMarksheets = saveSampleMarksheets;
|
|
39
|
+
const saveSampleTodoMark = (client, todoInput, markId) => {
|
|
40
|
+
const { timeTaken, score } = todoInput;
|
|
41
|
+
client.writeFragment({
|
|
42
|
+
id: `TodoMark:${markId}`,
|
|
43
|
+
data: {
|
|
44
|
+
score,
|
|
45
|
+
timeTaken: timeTaken,
|
|
46
|
+
},
|
|
47
|
+
fragment: (0, client_1.gql) `
|
|
48
|
+
fragment UpdatedTodoMark on TodoMark {
|
|
49
|
+
score
|
|
50
|
+
timeTaken
|
|
51
|
+
}
|
|
52
|
+
`,
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.saveSampleTodoMark = saveSampleTodoMark;
|
|
@@ -25,6 +25,7 @@ export interface ISaveTodosVar {
|
|
|
25
25
|
}
|
|
26
26
|
export declare type ISaveTodosData = RestrictedData<(graphqlNormalize & ITodo)[], 'saveTodos'>;
|
|
27
27
|
export declare function saveTodosCache(cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<ISaveTodosData>, options: ApolloUpdateOptions): void;
|
|
28
|
+
export declare const optimisticSaveTodos: (todo: ITodo, cardIndex: number, todoInput: ITodoInput) => ISaveTodosData;
|
|
28
29
|
export declare const ADD_TO_DAILY_STACK: import("@apollo/client").DocumentNode;
|
|
29
30
|
export interface IAddToDailyStackVar {
|
|
30
31
|
conceptIds: Id[];
|
|
@@ -37,8 +38,8 @@ export interface IRemoveFromDailyStackVar {
|
|
|
37
38
|
conceptId?: Id;
|
|
38
39
|
}
|
|
39
40
|
export declare type IRemoveFromDailyStackData = RestrictedData<(graphqlNormalize & IUserCompletedCard)[], 'removeFromDailyStack'>;
|
|
40
|
-
export declare const
|
|
41
|
-
export declare const
|
|
41
|
+
export declare const updateCacheOnRemoveFromDailyStack: (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IRemoveFromDailyStackData>, options: ApolloUpdateOptions) => void;
|
|
42
|
+
export declare const updateCacheOnAddToDailyStack: (cache: ApolloCache<any>, result: ApolloUpdateResultRestricted<IAddToDailyStackData>) => void;
|
|
42
43
|
export declare const REFRESH_DAILY_TASK: import("@apollo/client").DocumentNode;
|
|
43
44
|
export declare type IRefreshDailyTaskVar = null;
|
|
44
45
|
export declare type IRefreshDailyTaskData = RestrictedData<graphqlNormalize & ITodo, 'refreshDailyTask'>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
|
-
import {
|
|
2
|
+
import { PICTURE_FIELDS } from '../../fragments';
|
|
3
|
+
import { TODO, USER_COMPLETED_DATA, } from '../../query/restricted';
|
|
3
4
|
export const BUILD_TODO = gql `
|
|
4
5
|
mutation BuildTodo($buildTodo: BuildTodoInput!) {
|
|
5
6
|
restricted {
|
|
@@ -74,6 +75,22 @@ export function saveTodosCache(cache, result, options) {
|
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
}
|
|
78
|
+
export const optimisticSaveTodos = (todo, cardIndex, todoInput) => {
|
|
79
|
+
const { score, timeTaken } = todoInput;
|
|
80
|
+
const { marks } = todo;
|
|
81
|
+
const newMarks = [...marks];
|
|
82
|
+
newMarks[cardIndex] = { ...marks[cardIndex], score, timeTaken };
|
|
83
|
+
return {
|
|
84
|
+
restricted: {
|
|
85
|
+
saveTodos: [
|
|
86
|
+
{
|
|
87
|
+
...todo,
|
|
88
|
+
marks: newMarks,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
};
|
|
77
94
|
export const ADD_TO_DAILY_STACK = gql `
|
|
78
95
|
${PICTURE_FIELDS}
|
|
79
96
|
mutation AddToDailyStack($conceptIds: [Int!]!) {
|
|
@@ -131,44 +148,80 @@ export const REMOVE_FROM_DAILY_STACK = gql `
|
|
|
131
148
|
}
|
|
132
149
|
}
|
|
133
150
|
`;
|
|
134
|
-
export const
|
|
151
|
+
export const updateCacheOnRemoveFromDailyStack = (cache, result, options) => {
|
|
135
152
|
const { removeFromDailyStack } = result.data?.restricted || {};
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
153
|
+
const { variables } = options || {};
|
|
154
|
+
const { todoId } = variables || {};
|
|
155
|
+
if (!removeFromDailyStack || !removeFromDailyStack.length) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const toRemove = new Set(removeFromDailyStack.map(({ cardId }) => cardId));
|
|
159
|
+
const prevData = cache.readQuery({
|
|
160
|
+
query: USER_COMPLETED_DATA,
|
|
139
161
|
});
|
|
140
|
-
if (prevData
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
const newCompletedCards = prevData.completedCards.filter(({ id }) => !toRemove.has(id));
|
|
146
|
-
cache.writeFragment({
|
|
147
|
-
id: cache.identify({ id: userId, __typename: 'User' }),
|
|
162
|
+
if (prevData) {
|
|
163
|
+
const newCompletedCards = prevData.restricted.user.completedCards.filter(({ cardId }) => !toRemove.has(cardId));
|
|
164
|
+
cache.writeQuery({
|
|
165
|
+
query: USER_COMPLETED_DATA,
|
|
148
166
|
data: {
|
|
149
|
-
|
|
150
|
-
|
|
167
|
+
...prevData,
|
|
168
|
+
restricted: {
|
|
169
|
+
...prevData.restricted,
|
|
170
|
+
user: {
|
|
171
|
+
...prevData.restricted.user,
|
|
172
|
+
completedCards: newCompletedCards,
|
|
173
|
+
completedCardsCount: newCompletedCards.length,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
151
176
|
},
|
|
152
|
-
fragment: COMPLETED_CARDS,
|
|
153
177
|
});
|
|
154
178
|
}
|
|
179
|
+
if (todoId) {
|
|
180
|
+
const prevData = cache.readQuery({
|
|
181
|
+
variables: { id: todoId },
|
|
182
|
+
query: TODO,
|
|
183
|
+
});
|
|
184
|
+
if (prevData) {
|
|
185
|
+
const { marks } = prevData.restricted.todo;
|
|
186
|
+
cache.writeQuery({
|
|
187
|
+
query: TODO,
|
|
188
|
+
data: {
|
|
189
|
+
...prevData,
|
|
190
|
+
restricted: {
|
|
191
|
+
...prevData.restricted,
|
|
192
|
+
todo: {
|
|
193
|
+
...prevData.restricted.todo,
|
|
194
|
+
marks: marks.filter(({ cardId }) => !toRemove.has(Number(cardId))),
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
155
201
|
};
|
|
156
|
-
export const
|
|
202
|
+
export const updateCacheOnAddToDailyStack = (cache, result) => {
|
|
157
203
|
const { addToDailyStack } = result.data?.restricted || {};
|
|
158
|
-
const prevData = cache.
|
|
159
|
-
|
|
160
|
-
fragment: COMPLETED_CARDS,
|
|
204
|
+
const prevData = cache.readQuery({
|
|
205
|
+
query: USER_COMPLETED_DATA,
|
|
161
206
|
});
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
207
|
+
if (prevData && addToDailyStack) {
|
|
208
|
+
const newCompletedCards = [
|
|
209
|
+
...prevData.restricted.user.completedCards,
|
|
210
|
+
...addToDailyStack,
|
|
211
|
+
];
|
|
212
|
+
cache.writeQuery({
|
|
213
|
+
query: USER_COMPLETED_DATA,
|
|
167
214
|
data: {
|
|
168
|
-
|
|
169
|
-
|
|
215
|
+
...prevData,
|
|
216
|
+
restricted: {
|
|
217
|
+
...prevData.restricted,
|
|
218
|
+
user: {
|
|
219
|
+
...prevData.restricted.user,
|
|
220
|
+
completedCards: newCompletedCards,
|
|
221
|
+
completedCardsCount: newCompletedCards.length,
|
|
222
|
+
},
|
|
223
|
+
},
|
|
170
224
|
},
|
|
171
|
-
fragment: COMPLETED_CARDS,
|
|
172
225
|
});
|
|
173
226
|
}
|
|
174
227
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ApolloClient } from '@apollo/client';
|
|
2
|
-
import { IMarksheetInput } from './restricted';
|
|
2
|
+
import { IMarksheetInput, ITodoInput } from './restricted';
|
|
3
3
|
export declare const saveSampleMarksheets: (client: ApolloClient<any>, marksheetInput: IMarksheetInput, questionIndex: number) => void;
|
|
4
|
+
export declare const saveSampleTodoMark: (client: ApolloClient<any>, todoInput: ITodoInput, markId: number) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
1
2
|
import { SAMPLE_MARKSHEET, } from '../query';
|
|
2
3
|
export const saveSampleMarksheets = (client, marksheetInput, questionIndex) => {
|
|
3
4
|
const { timeTaken, choiceId, mark, marksheetId } = marksheetInput;
|
|
@@ -31,3 +32,19 @@ export const saveSampleMarksheets = (client, marksheetInput, questionIndex) => {
|
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
};
|
|
35
|
+
export const saveSampleTodoMark = (client, todoInput, markId) => {
|
|
36
|
+
const { timeTaken, score } = todoInput;
|
|
37
|
+
client.writeFragment({
|
|
38
|
+
id: `TodoMark:${markId}`,
|
|
39
|
+
data: {
|
|
40
|
+
score,
|
|
41
|
+
timeTaken: timeTaken,
|
|
42
|
+
},
|
|
43
|
+
fragment: gql `
|
|
44
|
+
fragment UpdatedTodoMark on TodoMark {
|
|
45
|
+
score
|
|
46
|
+
timeTaken
|
|
47
|
+
}
|
|
48
|
+
`,
|
|
49
|
+
});
|
|
50
|
+
};
|