Adrinalin4ik / Nestjs-Graphql-Tools

NestJS Graphql Tools is a flexible solution that provides a bunch of decorators for solving problems like n+1 request, filtering, sorting, pagination, polymorphic relation, graphql field extraction. It is fully based on decorators. To use it you can just add a decorator to your resolver.
GNU General Public License v3.0
79 stars 8 forks source link

fix(filters): Hasura won't let configure permission #17

Closed mgsasaki closed 1 year ago

mgsasaki commented 1 year ago

…here parameter

ERROR: { "code": "validation-failed", "error": "validation for the given role-based schema failed because expected default value of input value: \"where\"of input object \"Entity\" to be {} but received {name: \"FilterPropertyDecorator\"}", "path": "$.args[1].args" }

Adrinalin4ik commented 1 year ago

Hey, can you explain how to reproduce it?

mgsasaki commented 1 year ago
  1. Configure a query with filter on a NestJs project;
  2. Connect this project with Hasura (hasura/graphql-engine:v2.20.0.cli-migrations-v3) through remote schema;
  3. Enable remote schema permission;
  4. Configure the remote schema permission for a role and check the query with the filter parameter;
  5. When you try to save the permission, Hasura throw an error as described on the commit.
Adrinalin4ik commented 1 year ago

Not sure I understand how your change is fixing it. I was trying to repro with the latest hasura and I wasn't able to connect my app with this lib as a remote schema. The error is different. And you made this change only for filters but what about sorting?

Adrinalin4ik commented 1 year ago

I was able to repro. In order to fix it you have to understand for what reason I did this thing

 class EntitySortingInput extends SortingInputType {
    @Field({defaultValue: SORTING_DECORATOR_NAME_METADATA_KEY})
    _name_: string;
  }

Answering, I did it for a better experience of finding parameters in the resolver.

export const applyFilterParameter = (args: any[], target, property: string) => {
  const filterArgIndex = args.findIndex(x => x?._name_ === FILTER_DECORATOR_NAME_METADATA_KEY);
  if (filterArgIndex != -1) {
    const options = Reflect.getMetadata(FILTER_DECORATOR_OPTIONS_METADATA_KEY, target, property) as IFilterDecoratorParams;
    const customFields = Reflect.getMetadata(FILTER_DECORATOR_CUSTOM_FIELDS_METADATA_KEY, target, property) as Map<string, GraphqlFilterFieldMetadata>;
    args[filterArgIndex] = convertParameters(args[filterArgIndex], customFields, options);
  }
}

Your fix is not fixing it, because if you add sorting in your resolver it will break. I've implemented a good solution for this problem and also fixed a couple of other problems I wanted to fix before but postponed it.

the link to the PR: https://github.com/Adrinalin4ik/Nestjs-Graphql-Tools/pull/18 It was released under 0.7.11 version.

Adrinalin4ik commented 1 year ago

This fix was reimplemented in another PR https://github.com/Adrinalin4ik/Nestjs-Graphql-Tools/pull/18

mgsasaki commented 1 year ago

Thank you for working on it. I actually wasn't using sorting, only filter and select.