-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby): Fix wrongly skipping graphql filter cache (#21578)
* Fix wrongly skipping cache * Keys were both flattened to dotted chains and not and failed comparison * Additionally refactored so that we don't flatten too much * Add a helpful comment * Don't include comparator in index path * Add tests to test caching * Node8 support * Jeesh typobot, okay * Fix linting errors * More lint fixes * Update packages/gatsby/src/redux/__tests__/run-sift.js Co-Authored-By: Vladimir Razuvaev <vladimir.razuvaev@gmail.com> * Fix ts warnings Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
- Loading branch information
1 parent
be1d1aa
commit 4f68761
Showing
5 changed files
with
896 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,289 @@ | ||
import { createDbQueriesFromObject, dbQueryToSiftQuery } from "../query" | ||
|
||
describe(`DbQuery`, () => { | ||
it(`converts basic query`, () => { | ||
const query = createDbQueriesFromObject({ id: { $eq: `2` } }) | ||
expect(query).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"path": Array [ | ||
"id", | ||
], | ||
"query": Object { | ||
"comparator": "$eq", | ||
"value": "2", | ||
}, | ||
"type": "query", | ||
}, | ||
] | ||
`) | ||
expect(query.map(q => dbQueryToSiftQuery(q))).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"id": Object { | ||
"$eq": "2", | ||
}, | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
it(`converts nested query`, () => { | ||
const query = createDbQueriesFromObject({ | ||
internal: { value: { $eq: `2` } }, | ||
}) | ||
expect(query).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"path": Array [ | ||
"internal", | ||
"value", | ||
], | ||
"query": Object { | ||
"comparator": "$eq", | ||
"value": "2", | ||
}, | ||
"type": "query", | ||
}, | ||
] | ||
`) | ||
expect(query.map(q => dbQueryToSiftQuery(q))).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"internal.value": Object { | ||
"$eq": "2", | ||
}, | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
it(`converts branching nested query`, () => { | ||
const query = createDbQueriesFromObject({ | ||
internal: { value: { $eq: `2` }, otherValue: { $regex: /baz/ } }, | ||
}) | ||
expect(query).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"path": Array [ | ||
"internal", | ||
"value", | ||
], | ||
"query": Object { | ||
"comparator": "$eq", | ||
"value": "2", | ||
}, | ||
"type": "query", | ||
}, | ||
Object { | ||
"path": Array [ | ||
"internal", | ||
"otherValue", | ||
], | ||
"query": Object { | ||
"comparator": "$regex", | ||
"value": /baz/, | ||
}, | ||
"type": "query", | ||
}, | ||
] | ||
`) | ||
expect(query.map(q => dbQueryToSiftQuery(q))).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"internal.value": Object { | ||
"$eq": "2", | ||
}, | ||
}, | ||
Object { | ||
"internal.otherValue": Object { | ||
"$regex": /baz/, | ||
}, | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
it(`converts complex branching nested query`, () => { | ||
const query = createDbQueriesFromObject({ | ||
id: { $in: [`foo`] }, | ||
internal: { value: { $eq: `2` }, otherValue: { $regex: /baz/ } }, | ||
}) | ||
|
||
expect(query).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"path": Array [ | ||
"id", | ||
], | ||
"query": Object { | ||
"comparator": "$in", | ||
"value": Array [ | ||
"foo", | ||
], | ||
}, | ||
"type": "query", | ||
}, | ||
Object { | ||
"path": Array [ | ||
"internal", | ||
"value", | ||
], | ||
"query": Object { | ||
"comparator": "$eq", | ||
"value": "2", | ||
}, | ||
"type": "query", | ||
}, | ||
Object { | ||
"path": Array [ | ||
"internal", | ||
"otherValue", | ||
], | ||
"query": Object { | ||
"comparator": "$regex", | ||
"value": /baz/, | ||
}, | ||
"type": "query", | ||
}, | ||
] | ||
`) | ||
expect(query.map(q => dbQueryToSiftQuery(q))).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"id": Object { | ||
"$in": Array [ | ||
"foo", | ||
], | ||
}, | ||
}, | ||
Object { | ||
"internal.value": Object { | ||
"$eq": "2", | ||
}, | ||
}, | ||
Object { | ||
"internal.otherValue": Object { | ||
"$regex": /baz/, | ||
}, | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
it(`converts elemMatch`, () => { | ||
const query = createDbQueriesFromObject({ | ||
nested: { $elemMatch: { $eq: `foo` } }, | ||
}) | ||
expect(query).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"nestedQuery": Object { | ||
"path": Array [], | ||
"query": Object { | ||
"comparator": "$eq", | ||
"value": "foo", | ||
}, | ||
"type": "query", | ||
}, | ||
"path": Array [ | ||
"nested", | ||
], | ||
"type": "elemMatch", | ||
}, | ||
] | ||
`) | ||
expect(query.map(q => dbQueryToSiftQuery(q))).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"nested": Object { | ||
"$elemMatch": Object { | ||
"$eq": "foo", | ||
}, | ||
}, | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
it(`converts complex elemMatch`, () => { | ||
const query = createDbQueriesFromObject({ | ||
nested: { $elemMatch: { foo: { $eq: `foo` } } }, | ||
}) | ||
expect(query).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"nestedQuery": Object { | ||
"path": Array [ | ||
"foo", | ||
], | ||
"query": Object { | ||
"comparator": "$eq", | ||
"value": "foo", | ||
}, | ||
"type": "query", | ||
}, | ||
"path": Array [ | ||
"nested", | ||
], | ||
"type": "elemMatch", | ||
}, | ||
] | ||
`) | ||
expect(query.map(q => dbQueryToSiftQuery(q))).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"nested": Object { | ||
"$elemMatch": Object { | ||
"foo": Object { | ||
"$eq": "foo", | ||
}, | ||
}, | ||
}, | ||
}, | ||
] | ||
`) | ||
}) | ||
|
||
it(`converts nested elemMatch`, () => { | ||
const query = createDbQueriesFromObject({ | ||
nested: { $elemMatch: { foo: { $eq: `foo` }, bar: { $eq: `bar` } } }, | ||
}) | ||
expect(query).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"nestedQuery": Object { | ||
"path": Array [ | ||
"foo", | ||
], | ||
"query": Object { | ||
"comparator": "$eq", | ||
"value": "foo", | ||
}, | ||
"type": "query", | ||
}, | ||
"path": Array [ | ||
"nested", | ||
], | ||
"type": "elemMatch", | ||
}, | ||
Object { | ||
"nestedQuery": Object { | ||
"path": Array [ | ||
"bar", | ||
], | ||
"query": Object { | ||
"comparator": "$eq", | ||
"value": "bar", | ||
}, | ||
"type": "query", | ||
}, | ||
"path": Array [ | ||
"nested", | ||
], | ||
"type": "elemMatch", | ||
}, | ||
] | ||
`) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.