Skip to content
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

Supporting private fields and fields with no accessors #8

Open
hogancr opened this issue Jan 11, 2017 · 0 comments
Open

Supporting private fields and fields with no accessors #8

hogancr opened this issue Jan 11, 2017 · 0 comments

Comments

@hogancr
Copy link

hogancr commented Jan 11, 2017

My understanding is that this project wants to allow easy use of existing POJOs in your query classes, and the PropertyDataFetcher is providing this support. I've got some POJOs from a third-party developer that used public attributes rather than accessors, and as a result the getPropertyViaGetter method would fail to resolve the properties every time. It seems like it would be easy enough to add a getPropertyAsAttribute method that could execute when this one failed in order to support such POJOs.

I then got my third-party developer to generate accessors for all of the properties in the POJOs and found another problem. They added serialVersionUIDs as private static members (which I think is a pretty standard approach) as follows:

private static final long serialVersionUID = 1L;

This leads to an exception stack trace something like this because the serialVersionUID field is not accessible when building the schema, and I'm not sure what to do about that exactly...could be that adding an addFieldFilterPredicates or similar method to the schema config class would allow clients to further filter the fields returned by the Class.getDeclaredFields method in ReflectionUtils so that we can limit it somehow, or possibly just adding by default a predicate that only includes public fields. I'm not familiar enough with how this code is working to really make recommendations here, but is there a way to not get this exception when trying to build a schema off of something that has private fields?

...
Caused by: java.lang.IllegalStateException: Could not access method: Class org.springframework.util.ReflectionUtils can not access a member of class <X.Y.Z.PojoClass> with modifiers "private static final"
at org.springframework.util.ReflectionUtils.handleReflectionException(ReflectionUtils.java:277)
at org.springframework.util.ReflectionUtils.getField(ReflectionUtils.java:146)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.getFieldDefinition(GraphQLSchemaDfsTraversal.java:293)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.lambda$createGraphQLObjectTypeRecursively$1(GraphQLSchemaDfsTraversal.java:142)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal$$Lambda$8/1734769274.accept(Unknown Source)
at java.lang.Iterable.forEach(Iterable.java:75)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.createGraphQLObjectTypeRecursively(GraphQLSchemaDfsTraversal.java:141)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.createGraphQLFieldType(GraphQLSchemaDfsTraversal.java:317)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.getFieldDefinition(GraphQLSchemaDfsTraversal.java:284)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.lambda$createGraphQLObjectTypeRecursively$1(GraphQLSchemaDfsTraversal.java:142)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal$$Lambda$8/1734769274.accept(Unknown Source)
at java.lang.Iterable.forEach(Iterable.java:75)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.createGraphQLObjectTypeRecursively(GraphQLSchemaDfsTraversal.java:141)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.createGraphQLFieldType(GraphQLSchemaDfsTraversal.java:317)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.getFieldDefinition(GraphQLSchemaDfsTraversal.java:284)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.lambda$createGraphQLObjectTypeRecursively$1(GraphQLSchemaDfsTraversal.java:142)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal$$Lambda$8/1734769274.accept(Unknown Source)
at java.lang.Iterable.forEach(Iterable.java:75)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.createGraphQLObjectTypeRecursively(GraphQLSchemaDfsTraversal.java:141)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.createGraphQLFieldType(GraphQLSchemaDfsTraversal.java:317)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.getMethodDefinition(GraphQLSchemaDfsTraversal.java:252)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.lambda$createGraphQLObjectTypeRecursively$2(GraphQLSchemaDfsTraversal.java:148)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal$$Lambda$9/105622200.accept(Unknown Source)
at java.lang.Iterable.forEach(Iterable.java:75)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.createGraphQLObjectTypeRecursively(GraphQLSchemaDfsTraversal.java:147)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.findSchemaQueryRoot(GraphQLSchemaDfsTraversal.java:120)
at com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.traverse(GraphQLSchemaDfsTraversal.java:100)
at com.oembedler.moon.graphql.engine.GraphQLSchemaBuilder.buildSchema(GraphQLSchemaBuilder.java:51)
at <XYZ.SchemaConfiguration>.graphQLSchemaHolder(SchemaConfiguration.java:55)
at <XYZ.SchemaConfiguration$$EnhancerBySpringCGLIB$$3c229244.CGLIB$graphQLSchemaHolder$2()
at <XYZ.SchemaConfiguration>$$EnhancerBySpringCGLIB$$3c229244$$FastClassBySpringCGLIB$$4ac22a24.invoke()
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
at <XYZ.SchemaConfiguration>$$EnhancerBySpringCGLIB$$3c229244.graphQLSchemaHolder()
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 42 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant