Comments (10)
Can you please add a code snippet that results in the error.
from rejoiner.
BTW someone created an Kotlin example at https://github.com/dbaggett/medallion
from rejoiner.
The Kotlin example is useful to see, although unfortunately doesn't utilise the remove field functionality.
My first attempt was:
class AuthServiceSchemaModule : SchemaModule() {
@SchemaModification
val removeRegisterUserRemoteAddr = Type
.find(RegisterUserRequest.getDescriptor())
.removeField("remoteAddr")!!
This results in the error:
java.lang.NoSuchMethodException: com.google.api.graphql.rejoiner.SchemaModification.getDescriptor()
My Java is basic, but I think I can see why this is happening.
Line 228 in SchemaModule.java I think expects the only @SchemaModification annotations on a method to be for adding fields. As Kotlin creates a getter behind the scenes this is conflicting with the intentions of SchemaModule.
The decompiled Java code of this approach is:
public final class AuthServiceSchemaModule extends SchemaModule {
@NotNull
private final TypeModification removeRegisterUserRemoteAddr;
/** @deprecated */
// $FF: synthetic method
@SchemaModification
public static void removeRegisterUserRemoteAddr$annotations() {
}
@NotNull
public final TypeModification getRemoveRegisterUserRemoteAddr() {
return this.removeRegisterUserRemoteAddr;
}
Another thing I tried was adding the @JvmField annotation, which tells the compiler to use a java field. The problem here is that it appears to have created a field, but rather than assign the value inline it has done it from a constructor:
public final class AuthServiceSchemaModule extends SchemaModule {
@JvmField
@NotNull
public final TypeModification removeRegisterUserRemoteAddr;
/** @deprecated */
// $FF: synthetic method
@SchemaModification
public static void removeRegisterUserRemoteAddr$annotations() {
}
public AuthServiceSchemaModule() {
TypeModification var10001 = Type.find((GenericDescriptor)RegisterUserRequest.getDescriptor()).removeField("remoteAddr");
if (var10001 == null) {
Intrinsics.throwNpe();
}
this.removeRegisterUserRemoteAddr = var10001;
}
This approach results in the same error. Any ideas would be greatly appreciated.
Regards
Chris
from rejoiner.
I've got a little closer to a solution with this. It turns out that by prefixing the annotation with @field the compiler will ensure that the annotation is attached to the java backing field.
The generated code now looks more sensible, as follows:
public final class AuthServiceSchemaModule extends SchemaModule {
@SchemaModification
@JvmField
@NotNull
public final TypeModification removeRegisterUserRemoteAddr;
public AuthServiceSchemaModule() {
TypeModification var10001 = Type.find((GenericDescriptor)RegisterUserRequest.getDescriptor()).removeField("remoteAddr");
if (var10001 == null) {
Intrinsics.throwNpe();
}
this.removeRegisterUserRemoteAddr = var10001;
}
}
This still doesn't seem to have any effect however. I wonder if I'm misunderstanding the concept of removing fields.
I have a field for the remote users IP address in my GRPC service, which I want to populate from the servlet request rather than have supplied by the GraphQL called. My aim is to remove this field from the GraphQL schema.
I am on the wrong track here?
Chris
from rejoiner.
from rejoiner.
I can't find any way to have the value assigned inline, but it was suggested to me that the bytecode is likely the same. They seemed to think that in Java when values are assigned inline a default constructor is created by the compiler for the assignment.
from rejoiner.
Do you know why it's casting to GenericDescriptor? I wonder if you could look at the fields of TypeModification if you set a breakpoint.
As a temporary workaround could you include a Java SchemaModule that includes removeRegisterUserRemoteAddr?
from rejoiner.
Ohh, can you try Type.find("RegisterUserRequest")....
from rejoiner.
I'm not sure about the cast, but don't think it would make any difference.
I had tried using a string for the type name in addition to the getDescriptor approach with no noticeable difference. They both result in a RemoveFieldByName object with the values:
fieldNameToRemove = "remoteAddr"
typeName = "RegisterUserRequest"
I've also tried using the following Java code:
public class AuthServiceSchemaExtModule extends SchemaModule {
@SchemaModification
TypeModification removeRegisterUserRemoteAddr = Type
.find("RegisterUserRequest")
.removeField("remoteAddr");
@SchemaModification
TypeModification removeAuthenticateUserRemoteAddr = Type
.find(AuthenticateUserRequest.getDescriptor())
.removeField("remoteAddr");
}
But even that appears to have no effect.
I tried to follow your schema provider test -https://github.com/google/rejoiner/blob/7f18f8c6056cdb2f2cf54237b17856f08c794df4/rejoiner/src/test/java/com/google/api/graphql/rejoiner/SchemaProviderModuleTest.java
I'm a little confused though as even the comment suggests it may not work?
// TODO: this should be empty, currently type modifications only apply to types
// annotated with ExtraTypes.
from rejoiner.
I've been looking at this a little further as I'd love to be able to get it working.
Stepping through the modifyTypes method of the ProtoRegistry.java class, I notice that for my two defined type RegisterUserRequest and RegisterUserResponse, 2 additional mapping types have been created, Input_RegisterUserRequest, and Input_RegisterUserResponse.
The field removals are actually applied to my defined types (without the Input_ prefix), however the line
if (mapping.get(key) instanceof GraphQLObjectType) {
skips the modification code for each of the Input_ types. It seems that the Input types are the ones exposed in the schema (for input values), so it makes some sense that the expected fields aren't being removed. Should an Input_ type be produced for the return types as it seems to be (although this isn't causing any issue)? I'd probably have to put in a fair amount of effort to understand why the Input types are generated, but was hoping you may be able to point me in the right direction?
Regards
Chris
from rejoiner.
Related Issues (20)
- nicer JSON for standard wrappers HOT 11
- google_protobuf_Any value string HOT 1
- Rejoiner - Relay support thoughts HOT 5
- Sample/Example if backend GRPC services are in different language?
- Errors executing GraphQL request HOT 2
- Activity? HOT 4
- Request for Help on `GraphQL Stream (based on gRPC streaming)`
- Question: TypeModifcation - Replace field with context
- There is a vulnerability in Jetty: Java based HTTP/1.x, HTTP/2, Servlet, WebSocket Server 9.3.8.v20160314,upgrade recommended
- Missing "TestProto" component
- Question: rejoiner inside existing grpc service? HOT 2
- Exception when starting up Spring Boot 2.7.7/Java 17 app with Rejoiner HOT 2
- proto options not present in input messages
- Documentation website down. Open contributors?
- Documentation website down. Open contributors? HOT 3
- Archive the repository
- Quick Start Guide HOT 2
- How to get Proto object from the parent arguments? HOT 3
- modularization HOT 3
- errors HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rejoiner.