Skip to content

Commit ae67216

Browse files
committed
feat(ai): support nullable variables
1 parent dfce928 commit ae67216

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/ai/src/mocking/GrowingSchema.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ export class GrowingSchema {
132132
) {
133133
const query = operation.query;
134134

135-
// @todo handle variables
136135
const variables = operation.variables;
137136
const typeInfo = new TypeInfo(this.schema);
138137
const responsePath = [response.data];
@@ -191,7 +190,7 @@ export class GrowingSchema {
191190
const relatedVariable =
192191
variables?.[variableDefinition.variable.name.value];
193192

194-
if (!relatedVariable) {
193+
if (relatedVariable === undefined) {
195194
throw new GraphQLError(
196195
`Variable \`${variableDefinition.variable.name.value}\` is not defined`
197196
);

packages/ai/src/mocking/__tests__/GrowingSchema.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,18 @@ describe("GrowingSchema", () => {
230230

231231
it("handles scalar variables", () => {
232232
const query = gql`
233-
query Search($bookId: ID!, $arg: String!) {
233+
query Search($bookId: ID!, $arg: String!, $nullable: String) {
234234
book(id: $bookId) {
235235
__typename
236236
title
237-
anotherField(arg: $arg)
237+
anotherField(arg: $arg, nullable: $nullable)
238238
}
239239
}
240240
`;
241241
const variables = {
242242
bookId: "ASDF",
243243
arg: "QWERTY",
244+
nullable: null,
244245
};
245246
const response = {
246247
data: {
@@ -258,7 +259,7 @@ describe("GrowingSchema", () => {
258259
259260
type Book {
260261
title: String
261-
anotherField(arg: String!): Boolean
262+
anotherField(arg: String!, nullable: String): Boolean
262263
}
263264
`;
264265

@@ -282,7 +283,7 @@ describe("GrowingSchema", () => {
282283
name: "John Smith",
283284
},
284285
arg: {
285-
foo: "bar",
286+
foo: null,
286287
},
287288
};
288289
const response = {

0 commit comments

Comments
 (0)