Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Add Extensions metadata Decorator #1

Closed
wants to merge 4 commits into from

Conversation

hihuz
Copy link

@hihuz hihuz commented Jan 8, 2020

Should address issue MichalLytek#124 of https://github.com/MichalLytek/type-graphql

Implementation and tests look for the most part correct to me. The idea is to allow adding an arbitrary "extensions" field to any kind of entity in our gql schema.

With this, we would be able to write custom logic to handle authorization / permissions. In a middleware, we could read these specific extensions meta data and perform some checks there.

I need to double/triple check that we have access to this data as I expect it manually against our backend, and I also need to double check if it allows us to implement logic that would e.g. allow us to tag a Resolver or an ObjectType with some authorization logic that would apply to all of its child fields / methods

@hihuz hihuz force-pushed the feature/add-extensions-metadata branch from 9dfef70 to be3c0be Compare January 9, 2020 15:01
@hihuz hihuz force-pushed the feature/add-extensions-metadata branch from be3c0be to 0640e9e Compare January 9, 2020 16:42
@hihuz hihuz marked this pull request as ready for review January 9, 2020 16:48
@kontist kontist deleted a comment from codecov-io Jan 9, 2020
build() {
// TODO: disable next build attempts

this.classDirectives.reverse();
this.fieldDirectives.reverse();
this.classExtensions.reverse();
Copy link
Author

@hihuz hihuz Jan 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary or else the first decorator declared will have priority, e.g.:

@ObjectType
@Extensions({ duplicate: "one" })
@Extensions({ duplicate: "two" })

would end up with the object having duplicate: "one", it seems counter intuitive to me and I think this is why it was done in the "directives" feature in the same way. I would have added a code comment but since there was none in the directives PR, I'm not sure it would be appreciated. Will ask the question to the maintainer

@@ -57,3 +59,10 @@ export function ensureReflectMetadataExists() {
throw new ReflectMetadataMissingError();
}
}

export function flattenExtensions(
Copy link
Author

@hihuz hihuz Jan 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not such a fan of having a "util" just for this but I didn't see a proper alternative.

I could make it more generic by accepting a key by which we would flatten instead of hardcoding extensions, but since there is no other use through the codebase now it looked like premature abstraction to me

@hihuz
Copy link
Author

hihuz commented Jan 9, 2020

TODO tomorrow: Add code examples and documentation and then propose the PR to type-graphql, but we don't need that for our own use case so I'm opening the PR for review on our fork now.

@hihuz hihuz added the work in progress PR isn't ready to review yet label Jan 9, 2020
@kontist kontist deleted a comment from codecov-io Jan 10, 2020
@kontist kontist deleted a comment from codecov-io Jan 10, 2020
@hihuz hihuz force-pushed the feature/add-extensions-metadata branch from 5c48a1f to 9409d3d Compare January 10, 2020 17:20
@kontist kontist deleted a comment from codecov-io Jan 10, 2020
@hihuz hihuz removed the work in progress PR isn't ready to review yet label Jan 10, 2020
@codecov-io
Copy link

codecov-io commented Jan 10, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@fe6b306). Click here to learn what that means.
The diff coverage is 96.55%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master       #1   +/-   ##
=========================================
  Coverage          ?   95.21%           
=========================================
  Files             ?       77           
  Lines             ?     1359           
  Branches          ?      261           
=========================================
  Hits              ?     1294           
  Misses            ?       62           
  Partials          ?        3
Impacted Files Coverage Δ
src/schema/schema-generator.ts 96.74% <ø> (ø)
src/metadata/metadata-storage.ts 100% <100%> (ø)
src/metadata/utils.ts 94.73% <100%> (ø)
src/decorators/index.ts 100% <100%> (ø)
src/decorators/Extensions.ts 88.88% <88.88%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe6b306...e5ddc29. Read the comment docs.

@hihuz
Copy link
Author

hihuz commented Jan 30, 2020

My PR was merged over at type-graphql: MichalLytek#521, so we don't really need this one anymore. I will probably remove the fork as well, we can fork again later if we need

@hihuz hihuz closed this Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants