Skip to content

Commit

Permalink
Revert embedding snippets in objects and arrays due to performance is…
Browse files Browse the repository at this point in the history
…sues with such queries (#220)
  • Loading branch information
cleve-fauna authored Oct 5, 2023
1 parent df5e0be commit 1ff087f
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 609 deletions.
66 changes: 0 additions & 66 deletions __tests__/integration/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,70 +499,4 @@ describe("query can encode / decode QueryValue correctly", () => {
}
}
});

it("symbol arguments throw a TypeError", async () => {
expect.assertions(2);
// whack in a symbol
// @ts-expect-error Type 'symbol' is not assignable to type 'QueryValue'
let symbolValue: QueryValue = Symbol("foo");
try {
await client.query(fql`{ foo: ${symbolValue} }`);
} catch (e) {
if (e instanceof TypeError) {
expect(e.name).toBe("TypeError");
expect(e.message).toBe(
"Passing symbol as a QueryValue is not supported"
);
}
}
});

it("function arguments throw a TypeError", async () => {
expect.assertions(2);
// whack in a function
let fnValue: QueryValue = () => {};
try {
await client.query(fql`{ foo: ${fnValue} }`);
} catch (e) {
if (e instanceof TypeError) {
expect(e.name).toBe("TypeError");
expect(e.message).toBe(
"Passing function as a QueryValue is not supported"
);
}
}
});

it("symbol arguments throw a TypeError in arguments", async () => {
expect.assertions(2);
// whack in a symbol
// @ts-expect-error Type 'symbol' is not assignable to type 'QueryValue'
let symbolValue: QueryValue = Symbol("foo");
try {
await client.query(fql`foo`, { arguments: { foo: symbolValue } });
} catch (e: any) {
if (e instanceof ClientError && e.cause instanceof TypeError) {
expect(e.cause.name).toBe("TypeError");
expect(e.cause.message).toBe(
"Passing symbol as a QueryValue is not supported"
);
}
}
});

it("function arguments throw a TypeError in arguments", async () => {
expect.assertions(2);
// whack in a function
let fnValue: QueryValue = () => {};
try {
await client.query(fql`foo`, { arguments: { foo: fnValue } });
} catch (e: any) {
if (e instanceof ClientError && e.cause instanceof TypeError) {
expect(e.cause.name).toBe("TypeError");
expect(e.cause.message).toBe(
"Passing function as a QueryValue is not supported"
);
}
}
});
});
58 changes: 0 additions & 58 deletions __tests__/integration/template-format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,64 +109,6 @@ describe("query using template format", () => {
expect(response.data).toBe(true);
});

it("succeeds with deep nested expressions - example 2", async () => {
const str = "foo";
const otherStr = "bar";
const num = 6;
const otherNum = 3;
const deepFirst = fql`(${str} + ${otherStr})`;
const deeperBuilder = fql`(${num} + 3)`;
const innerQuery = fql`(${deeperBuilder} + ${otherNum})`;
const queryBuilder = fql`${deepFirst}.length + ${innerQuery}`;
const response = await client.query(queryBuilder);
expect(response.data).toBe(18);
});

it("succeeds with expressions nested within objects", async () => {
const arg = {
a: fql`1`,
b: fql`2`,
};
const queryBuilder = fql`${arg}`;
const response = await client.query(queryBuilder);
expect(response.data).toStrictEqual({ a: 1, b: 2 });
});

it("succeeds with expressions nested within arrays", async () => {
const arg = [fql`1`, fql`2`];
const queryBuilder = fql`${arg}`;
const response = await client.query(queryBuilder);
expect(response.data).toEqual([1, 2]);
});

it("succeeds with expressions nested within arrays and objects combined", async () => {
const arg = [
[fql`1`],
{
a: fql`1`,
b: fql`2`,
},
];
const queryBuilder = fql`${arg}`;
const response = await client.query(queryBuilder);
expect(response.data).toEqual([[1], { a: 1, b: 2 }]);
});

it("succeeds with multiple layers of nesting of arrays and objects", async () => {
const other = { a: fql`3`, b: fql`4` };
const arg = [
[fql`1 + ${fql`2`}`],
{
a: fql`1`,
b: fql`2`,
c: other,
},
];
const queryBuilder = fql`${arg}`;
const response = await client.query(queryBuilder);
expect(response.data).toEqual([[3], { a: 1, b: 2, c: { a: 3, b: 4 } }]);
});

it("succeeds with FQL string interpolation", async () => {
const codeName = "Alice";
const queryBuilder = fql`
Expand Down
79 changes: 46 additions & 33 deletions __tests__/unit/query-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("fql method producing Querys", () => {
const queryBuilder = fql`'foo'.length`;
const queryRequest = queryBuilder.toQuery();
expect(queryRequest.query).toEqual({ fql: ["'foo'.length"] });
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses with a string variable", () => {
Expand All @@ -15,7 +15,7 @@ describe("fql method producing Querys", () => {
expect(queryRequest.query).toEqual({
fql: [{ value: "foo" }, ".length"],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses with a number variable", () => {
Expand All @@ -25,7 +25,7 @@ describe("fql method producing Querys", () => {
expect(queryRequest.query).toEqual({
fql: ["'foo'.length == ", { value: { "@int": "8" } }],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses with a boolean variable", () => {
Expand All @@ -35,7 +35,7 @@ describe("fql method producing Querys", () => {
expect(queryRequest.query).toEqual({
fql: ["val.enabled == ", { value: true }],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses with a null variable", () => {
Expand All @@ -44,39 +44,27 @@ describe("fql method producing Querys", () => {
expect(queryRequest.query).toEqual({
fql: ["value: ", { value: null }],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses with an object variable", () => {
const obj = { foo: "bar", bar: "baz" };
const queryBuilder = fql`value: ${obj}`;
const queryRequest = queryBuilder.toQuery();
expect(queryRequest.query).toEqual({
fql: [
"value: ",
{ object: { bar: { value: "baz" }, foo: { value: "bar" } } },
],
fql: ["value: ", { value: { bar: "baz", foo: "bar" } }],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses with an object variable having a toQuery property", () => {
const obj = { foo: "bar", bar: "baz", toQuery: "hehe" };
const queryBuilder = fql`value: ${obj}`;
const queryRequest = queryBuilder.toQuery();
expect(queryRequest.query).toEqual({
fql: [
"value: ",
{
object: {
bar: { value: "baz" },
foo: { value: "bar" },
toQuery: { value: "hehe" },
},
},
],
fql: ["value: ", { value: { bar: "baz", foo: "bar", toQuery: "hehe" } }],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses with an array variable", () => {
Expand All @@ -86,16 +74,10 @@ describe("fql method producing Querys", () => {
expect(queryRequest.query).toEqual({
fql: [
"value: ",
{
array: [
{ value: { "@int": "1" } },
{ value: { "@int": "2" } },
{ value: { "@int": "3" } },
],
},
{ value: [{ "@int": "1" }, { "@int": "2" }, { "@int": "3" }] },
],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses with multiple variables", () => {
Expand All @@ -106,7 +88,7 @@ describe("fql method producing Querys", () => {
expect(queryRequest.query).toEqual({
fql: [{ value: "bar" }, ".length == ", { value: { "@int": "20" } }],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses nested expressions", () => {
Expand All @@ -122,7 +104,7 @@ describe("fql method producing Querys", () => {
{ fql: ["Math.add(", { value: { "@int": "17" } }, ", 3)"] },
],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses deep nested expressions", () => {
Expand Down Expand Up @@ -150,7 +132,38 @@ describe("fql method producing Querys", () => {
},
],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});

it("adds headers if passed in", () => {
const str = "baz";
const num = 17;
const innerQuery = fql`Math.add(${num}, 3)`;
const queryBuilder = fql`${str}.length == ${innerQuery}`;
const queryRequest = queryBuilder.toQuery({
linearized: true,
query_timeout_ms: 600,
max_contention_retries: 4,
query_tags: { a: "tag" },
traceparent: "00-750efa5fb6a131eb2cf4db39f28366cb-5669e71839eca76b-00",
typecheck: false,
});
expect(queryRequest).toMatchObject({
linearized: true,
query_timeout_ms: 600,
max_contention_retries: 4,
query_tags: { a: "tag" },
traceparent: "00-750efa5fb6a131eb2cf4db39f28366cb-5669e71839eca76b-00",
typecheck: false,
});
expect(queryRequest.query).toEqual({
fql: [
{ value: "baz" },
".length == ",
{ fql: ["Math.add(", { value: { "@int": "17" } }, ", 3)"] },
],
});
expect(queryRequest.arguments).toStrictEqual({});
});

it("parses with FQL string interpolation", async () => {
Expand All @@ -167,6 +180,6 @@ describe("fql method producing Querys", () => {
'\n "Hello, #{name}"\n ',
],
});
expect(queryRequest.arguments).toBeUndefined();
expect(queryRequest.arguments).toStrictEqual({});
});
});
Loading

0 comments on commit 1ff087f

Please sign in to comment.