Closed
Description
Here's a code snippet:
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.coxautodev.graphql.tools.SchemaParser;
import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
public class Fooooo {
public static void main(String[] args) {
String schemaString = ""
+ "schema { query: Query } "
+ "type Query { foo: Interface1 } "
+ "interface Interface1 { field1(arg1: Int arg2: Int): Int } "
+ "type Type1 implements Interface1 { field1(arg1: Int arg2: Int): Int }";
GraphQLSchema makeExecutableSchema = SchemaParser.newParser()
.schemaString(schemaString)
.dictionary(Type1.class)
.resolvers(new FakeQueryResolver())
.build()
.makeExecutableSchema();
GraphQL graphQL = GraphQL.newGraphQL(makeExecutableSchema).build();
}
public static class FakeQueryResolver implements GraphQLQueryResolver {
public Interface1 foo() {
return new Type1();
}
}
public static interface Interface1 {
public int field1(int arg1, int arg2);
}
public static class Type1 implements Interface1 {
@Override
public int field1(int arg1, int arg2) {
return 0;
}
}
}
The last line in the main method will cause this error:
Exception in thread "main" graphql.schema.validation.InvalidSchemaException: invalid schema:
object type 'Type1' does not implement interface 'Interface1' because field 'field1' argument 'arg1' is defined differently
object type 'Type1' does not implement interface 'Interface1' because field 'field1' argument 'arg2' is defined differently
at graphql.schema.GraphQLSchema$Builder.build(GraphQLSchema.java:344)
at com.coxautodev.graphql.tools.SchemaObjects.toSchema(SchemaObjects.kt:27)
at com.coxautodev.graphql.tools.SchemaParser.makeExecutableSchema(SchemaParser.kt:130)
at Fooooo.main(Fooooo.java:20)
If you get rid of one of the arguments like this:
public class Fooooo {
public static void main(String[] args) {
String schemaString = ""
+ "schema { query: Query } "
+ "type Query { foo: Interface1 } "
+ "interface Interface1 { field1(arg1: Int): Int } "
+ "type Type1 implements Interface1 { field1(arg1: Int): Int }";
GraphQLSchema makeExecutableSchema = SchemaParser.newParser()
.schemaString(schemaString)
.dictionary(Type1.class)
.resolvers(new FakeQueryResolver())
.build()
.makeExecutableSchema();
GraphQL graphQL = GraphQL.newGraphQL(makeExecutableSchema).build();
}
public static class FakeQueryResolver implements GraphQLQueryResolver {
public Interface1 foo() {
return new Type1();
}
}
public static interface Interface1 {
public int field1(int arg1);
}
public static class Type1 implements Interface1 {
@Override
public int field1(int arg1) {
return 0;
}
}
}
Then the code works completely fine.