From acbc4400c5b394df655354e6e29132e9707939fe Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Wed, 27 Sep 2023 16:02:25 -0500 Subject: [PATCH] update query work --- examples/todo-app/src/resources/TodoResource.ts | 9 ++------- packages/endpoint/src/queryEndpoint.ts | 12 +++++------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/examples/todo-app/src/resources/TodoResource.ts b/examples/todo-app/src/resources/TodoResource.ts index cd089155a0c8..d886d6cd2632 100644 --- a/examples/todo-app/src/resources/TodoResource.ts +++ b/examples/todo-app/src/resources/TodoResource.ts @@ -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, ); diff --git a/packages/endpoint/src/queryEndpoint.ts b/packages/endpoint/src/queryEndpoint.ts index dddd277a588a..15c9708169c1 100644 --- a/packages/endpoint/src/queryEndpoint.ts +++ b/packages/endpoint/src/queryEndpoint.ts @@ -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, @@ -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; }