Skip to content

Commit

Permalink
update query work
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Oct 9, 2023
1 parent ab99520 commit acbc440
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
9 changes: 2 additions & 7 deletions examples/todo-app/src/resources/TodoResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ export const TodoResource = createPlaceholderResource({
});

export const queryRemainingTodos = new Query(
new schema.All(Todo),
(entries, { userId } = {}) => {
if (userId !== undefined)
return entries.filter((todo) => todo.userId === userId && !todo.completed)
.length;
return entries.filter((todo) => !todo.completed).length;
},
TodoResource.getList.schema,
(entries) => entries && entries.filter((todo) => !todo.completed).length,
);
12 changes: 5 additions & 7 deletions packages/endpoint/src/queryEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ export class Query<

protected createQuerySchema(schema: SchemaSimple) {
const query = Object.create(schema);
query.denormalize = (
{ args, input }: { args: P; input: any },
_: P,
unvisit: any,
) => {
query.denormalize = (input: any, args: P, unvisit: any) => {
if (input === undefined) return undefined;
const value = (schema as any).denormalize(input, args, unvisit);
const value = unvisit(input, schema); //(schema as any).denormalize(input, args, unvisit);
return typeof value === 'symbol'
? undefined
: this.process(value, ...args);
};
// anywhere in the hierarchy
if ('key' in schema) query.key = `QUERY ${schema.key}`;
query.infer = (
args: any,
indexes: any,
Expand All @@ -56,7 +54,7 @@ export class Query<
) => any,
entities: EntityTable,
) => {
return { args, input: recurse(schema, args, indexes, entities) };
return recurse(schema, args, indexes, entities);
};
return query;
}
Expand Down

0 comments on commit acbc440

Please sign in to comment.