-
-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix interface resolvers with custom schemaName #567
Fix interface resolvers with custom schemaName #567
Conversation
As an aside, I tried to create a new test case for this but kept having weird errors. I tried to create a new interface: @InterfaceType()
abstract class FooInterface {
@Field()
fooInterfaceField: string;
}
@ObjectType({ implements: FooInterface })
class FooImplementation implements FooInterface {
fooInterfaceField: string;
@Field()
otherField: string;
} but whenever I wrote a query that returned
Which was... strange. |
Codecov Report
@@ Coverage Diff @@
## master #567 +/- ##
=======================================
Coverage 95.01% 95.01%
=======================================
Files 77 77
Lines 1363 1363
Branches 264 264
=======================================
Hits 1295 1295
Misses 65 65
Partials 3 3
Continue to review full report at Codecov.
|
Figured out that this was because of #568. I can re-write the test case to not latch onto the existing interfaces/objects. @MichalLytek Assuming this looks good, would it be possible to backport this and release 0.17.6? I'm having some issues in my project that would be solved with this -- as well as the existing issue where middlewares are not applied for interface fields being a potential(?) security issue. (and thanks as always for the awesome project!!!) |
I feel like it's a treatment of symptoms, not the cure for the disease. The problem is that we copy the interface field config, not the metadata, so as interfaces has no resolvers, object types does not have that too: type-graphql/src/schema/schema-generator.ts Lines 352 to 363 in 1ed5902
Implementing So I would suggest changing that part to fix the field name mapping issue 😉
This would also be fixed by the metadata copy approach - the middlewares would be applied for each corresponding object type field resolver. |
I'm not sure why that's an issue. Or, well, I'm not really sure what the alternative is. Since we are literally copying the fields from the interface to the object, and the interface is the one that knows how to resolve the field, why not just implement type-graphql/src/schema/schema-generator.ts Lines 225 to 241 in 1ed5902
Here, when we're generating I can think of one alternative that doesn't do this, but I'm not sure if it's any better: Forgo copying the fields and "manually" construct them from the original interface metadata. This would mean in |
It makes no sense to change this logic as it might affect some other parts and result in regression. Let's fix that in this simple way, as |
@MichalLytek Can this particular change be backported to the 0.17.x line? I'm running into an issue where an interface field isn't running the middleware because of this. |
I'm afraid I don't have time for this 😞 |
Fixes #566
New to this codebase, open to feedback!
As an aside, thedefaultFieldResolver
function just does the check if this is a function, if so, call it, otherwise return it as is thing.Edit: I changed to use the
createBasicFieldResolver
function. It looks like it could also be extended to the advanced resolver type to support external interface resolvers? Also, I think that the status quo (before this PR) wouldn't apply any auth checking to fields defined on interfaces since it doesn't run any middlewares.