Skip to content

Commit

Permalink
fix the typings: currently cannot pass native values as field selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-burel committed Mar 26, 2021
1 parent ee1d6a2 commit e2a829d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 12 additions & 4 deletions packages/graphql/tests/selectorTypings.test.ts
Expand Up @@ -3,23 +3,31 @@ import { VulcanSelector } from "../typings";
describe("vulcan/graphql/selector typings", () => {
test("basic selectors are working ok", () => {
const sampleFieldSelector: VulcanSelector = {
foo: 2,
foo: { _eq: 2 },
};
const sampleFieldAndConditionSelector: VulcanSelector = {
foo: { _gt: 2, _gte: 3 },
};
});
test("selector with operators", () => {
const sampleOperatorSelector: VulcanSelector = {
_or: [{ foo: 2 }, { bar: 3 }],
_or: [{ foo: { _eq: 2 } }, { bar: { _eq: 3 } }],
};
const sampleOperatorConditionSelector: VulcanSelector = {
_or: [{ foo: 2 }, { bar: { _gt: 3 } }],
_or: [{ foo: { _eq: 2 } }, { bar: { _gt: 3 } }],
};
});
test("works with a generic", () => {
const sampleFieldAndConditionSelectorWithModel: VulcanSelector<{
bar: number;
}> = { bar: 2, foo: 3 };
}> = { bar: { _eq: 2 } /*, foo: 3 */ };
});
test.skip("works with native values", () => {
// Currently you have to write bar: { _eq: 2}, you cannot write { bar: 2}
/*
const sampleFieldAndConditionSelectorWithModel: VulcanSelector<{
bar: number;
}> = { bar: 2 };
*/
});
});
8 changes: 5 additions & 3 deletions packages/graphql/typings.ts
Expand Up @@ -151,7 +151,7 @@ type VulcanSelectorSortOption = "asc" | "desc";
*/

type FieldSelector<TModel = any> = {
[key in keyof TModel]?: string | number | boolean | null | ConditionSelector;
[key in keyof TModel]?: ConditionSelector; // TODO: we cannot yet pass native values | string | number | boolean | null | ;
} &
{ [key in PossibleOperators]?: never };

Expand All @@ -174,7 +174,7 @@ type PossibleConditions = keyof ConditionSelector;

type PossibleOperators = "_and" | "_or" | "_not";
type OperatorSelector<TModel = any> = {
[key in PossibleOperators]?: Array<FieldSelector>; // Array<VulcanSelector<TModel>>; //VulcanInnerSelector<TModel>>;
[key in PossibleOperators]?: Array<FieldSelector<TModel>>; // Array<VulcanSelector<TModel>>; //VulcanInnerSelector<TModel>>;
};

// Field selector = { foo: 2} where foo is part of the model
Expand All @@ -197,7 +197,9 @@ type OperatorSelector<TModel = any> = {
* { _and: [{size:2}, {name: "hello"}], bar: 3}
*/

export type VulcanSelector<TModel = any> = FieldSelector | OperatorSelector;
export type VulcanSelector<TModel = any> =
| FieldSelector<TModel>
| OperatorSelector<TModel>;

// Inputs
export interface SingleInput<TModel = any> extends QueryInput<TModel> {
Expand Down

0 comments on commit e2a829d

Please sign in to comment.