Skip to content

Commit cc6da94

Browse files
committed
keep old schema in case of error
1 parent 25cb8b3 commit cc6da94

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/ai/src/mocking/GrowingSchema.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ export class GrowingSchema {
6969
) {
7070
const query = operation.query;
7171

72-
if (!this.seenQueries.has(query)) {
73-
this.seenQueries.add(query);
74-
this.mergeQueryIntoSchema(operation, response);
75-
}
76-
// @todo handle variables
77-
// const variables = operation.variables;
72+
const previousSchema = this.schema;
73+
74+
try {
75+
if (!this.seenQueries.has(query)) {
76+
this.seenQueries.add(query);
77+
this.mergeQueryIntoSchema(operation, response);
78+
}
7879

79-
this.validateResponseAgainstSchema(query, operation, response);
80+
this.validateResponseAgainstSchema(query, operation, response);
81+
} catch (e) {
82+
this.schema = previousSchema;
83+
throw e;
84+
}
8085
}
8186

8287
public mergeQueryIntoSchema(
@@ -88,6 +93,8 @@ export class GrowingSchema {
8893
) {
8994
const query = operation.query;
9095

96+
// @todo handle variables
97+
// const variables = operation.variables;
9198
const typeInfo = new TypeInfo(this.schema);
9299
const responsePath = [response.data];
93100

0 commit comments

Comments
 (0)