graphql-java-kickstart / graphql-java-tools

A schema-first tool for graphql-java inspired by graphql-tools for JS
https://www.graphql-java-kickstart.com/tools/
MIT License
810 stars 174 forks source link

Can't share class with input type #60

Closed also closed 7 years ago

also commented 7 years ago

Trying to use the same class with a normal type and input type in the same schema results in an java.lang.IllegalArgumentException: value already present exception for the class in question.

import com.coxautodev.graphql.tools.GraphQLMutationResolver;
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.coxautodev.graphql.tools.SchemaParser;

public class Example implements GraphQLQueryResolver, GraphQLMutationResolver {
  public static void main(String... args) {
    SchemaParser.newParser()
        .schemaString(
            "type Value { s: String }" +
            "type ValueInput { s: String }" +
            "type Query { get: Value! }" +
            "type Mutation { set(value: ValueInput): String! }"
        )
    .resolvers(new Example())
    .build();
  }

  public Value get() { return new Value(); }

  public String set(Value value) { return value.getS(); }

  static class Value {
    private String s;
    public String getS() { return s; }
    public void setS(String s) { this.s = s; }
  }
}

Running this with graphql-java-tools 4.1.0 throws

Exception in thread "main" com.coxautodev.graphql.tools.SchemaClassScannerError: Error creating bimap of type => class
    at com.coxautodev.graphql.tools.SchemaClassScanner.validateAndCreateParser(SchemaClassScanner.kt:126)
    at com.coxautodev.graphql.tools.SchemaClassScanner.scanForClasses(SchemaClassScanner.kt:96)
    at com.coxautodev.graphql.tools.SchemaParserBuilder.build(SchemaParserBuilder.kt:126)
    at Example.main(Example.java:15)
Caused by: java.lang.IllegalArgumentException: value already present: class Example$Value
    at com.google.common.collect.HashBiMap.put(HashBiMap.java:287)
    at com.google.common.collect.HashBiMap.put(HashBiMap.java:262)
    at com.coxautodev.graphql.tools.SchemaClassScanner.validateAndCreateParser(SchemaClassScanner.kt:123)
    ... 3 more

Explicitly adding the name and class with dictionary results in a similar exception.

rsmkrishna commented 6 years ago

I am also facing same issue , using graphql-java 6.0 and graphql-java-tool 4.3.0. kindly help to know the rite approach to solve the issue. Thanks in advance.