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

GraphQLObjectMapper is throwing exception when building Classes Hierarchy #15

Open
alissongodoi opened this issue May 8, 2017 · 1 comment

Comments

@alissongodoi
Copy link

alissongodoi commented May 8, 2017

log.txt
GraphQLObjectMapper is throwing exception in the typeArguments stack. It follows attached the log.

at java.util.Stack.peek(Unknown Source) ~[na:1.8.0_121]
at com.bretpatterson.schemagen.graphql.impl.GraphQLObjectMapper.getClassFromType(GraphQLObjectMapper.java:742) ~[schemagen-graphql-1.0.2.jar:na]

Basically I have the following classes:

public abstract class BaseEntity<ID> implements IdentifiedObject<ID>, VersionedEntity {
   @Id
   private ID id;

   public ID getId() {
       return id;
   }
   public void setId(ID id) {
       this.id=id;
   }	
}
public class Person extends BaseEntity<Long> implements IdentifiedObject<Long> {
    // Person details
}

It fails in the build:

@GraphQLController
public class KeyValueStoreController {
	  @GraphQLIgnore
	  private Map<String,Person> dataStore = new HashMap<String,Person>();
	  
	  public KeyValueStoreController() {
		  Person c = new Person();
		  c.setFirstName("Alisson");
		  c.setLastName("Godoi");
		  c.setId(1L);
		  dataStore.put("1", c);
	  }
	  
	  @GraphQLQuery(name="get")
	  public Person getValue(@GraphQLParam(name="key") String key) {
	     return dataStore.get(key);
	  }
	  
	  @GraphQLMutation(name="put")
	  public Customer setValue(String key, Customer value) {
	  	dataStore.put(key,value);
	  	return value;
	  }
}

KeyValueStoreController key = new KeyValueStoreController();
ObjectMapper objectMapper = new ObjectMapper();
GraphQLSchema schema = GraphQLSchemaBuilder.newBuilder()
    .registerTypeFactory(new JacksonTypeFactory(objectMapper))
    .registerGraphQLControllerObjects(ImmutableList.<Object>of(key))
    .build();

typeArguments variable is empty. It is trying to fetch variable type ID for the method BaseEntity.getId()
getClassFromType(typeArguments.peek().get(((TypeVariable<?>) type).getName()));

@cliedeman
Copy link
Contributor

Hi @alissongodoi

I have created a fix for this issue in PR #17.

The cause was the library not handling the case Person extends Entity correctly.

I have added some code using getSuperclass() to cater for this Scenario.

If the meantime you can create a custom type mapper to workaround the problem (not a real solution I know).

Ciaran

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

2 participants