Skip to content

Commit

Permalink
nullable checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ssanjay1 committed Jul 14, 2024
1 parent 9ecc601 commit b5ccec3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ export const queryTakesAllParameterTypes = {
type: 'struct',
},
twoDimensionalAggregation: {
nullable: false,
twoDimensionalAggregation: {
keyType: 'string',
valueType: 'double',
},
type: 'twoDimensionalAggregation',
},
threeDimensionalAggregation: {
nullable: false,
threeDimensionalAggregation: {
keyType: 'range',
keySubtype: 'date',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const queryTakesAllParameterTypes = {
twoDimensionalAggregation: {
type: 'twoDimensionalAggregation',
twoDimensionalAggregation: { keyType: 'string', valueType: 'double' },
nullable: false,
},
threeDimensionalAggregation: {
type: 'threeDimensionalAggregation',
Expand All @@ -55,6 +56,7 @@ export const queryTakesAllParameterTypes = {
keySubtype: 'date',
valueType: { keyType: 'range', keySubtype: 'timestamp', valueType: 'date' },
},
nullable: false,
},
},
output: { type: 'string', nullable: false },
Expand Down
11 changes: 11 additions & 0 deletions packages/client/src/queries/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ describe("queries", () => {
}, { key: "Q-AFO", groups: [] }]);
});

it("throws when response is null and response is non-nullable", async () => {
try {
const result = await client(addOne)({ n: 3 });
expect.fail("Should not reach here");
} catch (e) {
expect((e as Error).message).toMatch(
`Got null response when nullable was not allowed`,
);
}
});

it("three dimensional aggs request/response works", async () => {
const result = await client(acceptsThreeDimensionalAggregationFunction)({
aggFunction: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ export function wireQueryDataTypeToQueryDataTypeDefinition<
return {
type: "twoDimensionalAggregation",
twoDimensionalAggregation: get2DQueryAggregationProps(input),
nullable: false,
};

case "threeDimensionalAggregation":
return {
type: "threeDimensionalAggregation",
threeDimensionalAggregation: get3DQueryAggregationProps(input),
nullable: false,
};

case "null":
Expand Down
7 changes: 7 additions & 0 deletions packages/shared.test/src/stubs/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export const addOneQueryRequest: ExecuteQueryRequest = {
},
};

export const addOneQueryRequestWithNoResponse: ExecuteQueryRequest = {
parameters: {
n: 3,
},
};

export const addOneQueryResponse: ExecuteQueryResponse = {
value: 3,
};
Expand Down Expand Up @@ -228,6 +234,7 @@ export const queryRequestHandlers: {
} = {
[addOneQueryType.apiName]: {
[JSON.stringify(addOneQueryRequest)]: addOneQueryResponse,
[JSON.stringify(addOneQueryRequestWithNoResponse)]: { value: undefined },
},
[queryTypeReturnsStruct.apiName]: {
[JSON.stringify(queryTypeReturnsStructRequest)]:
Expand Down

0 comments on commit b5ccec3

Please sign in to comment.