From 118c471b31a81b2756d439228da3ddba9fbacba3 Mon Sep 17 00:00:00 2001 From: Kay Roepke Date: Fri, 18 Sep 2015 13:29:47 +0200 Subject: [PATCH 1/2] implement GraphQLType in abstract class to handle equals/hashcode for every implementation - according to the spec no two types can have the same name - looking up possible implementations of interfaces relies on .equals, when used with DI pointer equality breaks --- .../graphql/schema/AbstractGraphQLType.java | 32 +++++++++++++++++++ .../java/graphql/schema/GraphQLEnumType.java | 9 ++---- .../schema/GraphQLInputObjectType.java | 10 ++---- .../graphql/schema/GraphQLInterfaceType.java | 12 ++----- src/main/java/graphql/schema/GraphQLList.java | 7 ++-- .../java/graphql/schema/GraphQLNonNull.java | 3 +- .../graphql/schema/GraphQLObjectType.java | 14 ++------ .../graphql/schema/GraphQLScalarType.java | 12 ++----- .../graphql/schema/GraphQLTypeReference.java | 13 ++------ .../java/graphql/schema/GraphQLUnionType.java | 11 ++----- 10 files changed, 53 insertions(+), 70 deletions(-) create mode 100644 src/main/java/graphql/schema/AbstractGraphQLType.java diff --git a/src/main/java/graphql/schema/AbstractGraphQLType.java b/src/main/java/graphql/schema/AbstractGraphQLType.java new file mode 100644 index 0000000000..b4dc1d8c01 --- /dev/null +++ b/src/main/java/graphql/schema/AbstractGraphQLType.java @@ -0,0 +1,32 @@ +package graphql.schema; + +import static graphql.Assert.assertNotNull; + +public class AbstractGraphQLType implements GraphQLType { + private final String name; + + public AbstractGraphQLType(String name) { + assertNotNull(name, "name can't null"); + this.name = name; + } + + public String getName() { + return name.equals("") ? null : name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AbstractGraphQLType that = (AbstractGraphQLType) o; + + return getName().equals(that.getName()); + + } + + @Override + public int hashCode() { + return name.hashCode(); + } +} diff --git a/src/main/java/graphql/schema/GraphQLEnumType.java b/src/main/java/graphql/schema/GraphQLEnumType.java index b7a87198fd..ca4fa83bef 100644 --- a/src/main/java/graphql/schema/GraphQLEnumType.java +++ b/src/main/java/graphql/schema/GraphQLEnumType.java @@ -11,9 +11,8 @@ import static graphql.Assert.assertNotNull; -public class GraphQLEnumType implements GraphQLType, GraphQLInputType, GraphQLOutputType, GraphQLUnmodifiedType { +public class GraphQLEnumType extends AbstractGraphQLType implements GraphQLType, GraphQLInputType, GraphQLOutputType, GraphQLUnmodifiedType { - private final String name; private final String description; private final Map valueDefinitionMap = new LinkedHashMap<>(); @@ -46,8 +45,8 @@ public List getValues() { public GraphQLEnumType(String name, String description, List values) { + super(name); assertNotNull(name, "name can't be null"); - this.name = name; this.description = description; buildMap(values); } @@ -58,10 +57,6 @@ private void buildMap(List values) { } } - public String getName() { - return name; - } - public String getDescription() { return description; } diff --git a/src/main/java/graphql/schema/GraphQLInputObjectType.java b/src/main/java/graphql/schema/GraphQLInputObjectType.java index ffb906ca36..33debc7b4f 100644 --- a/src/main/java/graphql/schema/GraphQLInputObjectType.java +++ b/src/main/java/graphql/schema/GraphQLInputObjectType.java @@ -8,18 +8,16 @@ import static graphql.Assert.assertNotNull; -public class GraphQLInputObjectType implements GraphQLType, GraphQLInputType, GraphQLUnmodifiedType, GraphQLNullableType { +public class GraphQLInputObjectType extends AbstractGraphQLType implements GraphQLInputType, GraphQLUnmodifiedType, GraphQLNullableType { - private final String name; private final String description; private final Map fieldMap = new LinkedHashMap<>(); public GraphQLInputObjectType(String name, String description, List fields) { - assertNotNull(name, "name can't be null"); + super(name); assertNotNull(fields, "fields can't be null"); - this.name = name; this.description = description; buildMap(fields); } @@ -30,10 +28,6 @@ private void buildMap(List fields) { } } - public String getName() { - return name; - } - public String getDescription() { return description; } diff --git a/src/main/java/graphql/schema/GraphQLInterfaceType.java b/src/main/java/graphql/schema/GraphQLInterfaceType.java index 07c5bd276c..1e8979ee03 100644 --- a/src/main/java/graphql/schema/GraphQLInterfaceType.java +++ b/src/main/java/graphql/schema/GraphQLInterfaceType.java @@ -8,18 +8,16 @@ import static graphql.Assert.assertNotNull; -public class GraphQLInterfaceType implements GraphQLType, GraphQLOutputType, GraphQLFieldsContainer, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { +public class GraphQLInterfaceType extends AbstractGraphQLType implements GraphQLOutputType, GraphQLFieldsContainer, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { - private final String name; private final String description; private final Map fieldDefinitionsByName = new LinkedHashMap<>(); private final TypeResolver typeResolver; public GraphQLInterfaceType(String name, String description, List fieldDefinitions, TypeResolver typeResolver) { - assertNotNull(name, "name can't null"); + super(name); assertNotNull(typeResolver, "typeResolver can't null"); assertNotNull(fieldDefinitions, "fieldDefinitions can't null"); - this.name = name; this.description = description; buildDefinitionMap(fieldDefinitions); this.typeResolver = typeResolver; @@ -40,10 +38,6 @@ public List getFieldDefinitions() { return new ArrayList<>(fieldDefinitionsByName.values()); } - public String getName() { - return name; - } - public String getDescription() { return description; } @@ -55,7 +49,7 @@ public TypeResolver getTypeResolver() { @Override public String toString() { return "GraphQLInterfaceType{" + - "name='" + name + '\'' + + "name='" + getName() + '\'' + ", description='" + description + '\'' + ", fieldDefinitionsByName=" + fieldDefinitionsByName + ", typeResolver=" + typeResolver + diff --git a/src/main/java/graphql/schema/GraphQLList.java b/src/main/java/graphql/schema/GraphQLList.java index 3368b5f3dc..e7c010531f 100644 --- a/src/main/java/graphql/schema/GraphQLList.java +++ b/src/main/java/graphql/schema/GraphQLList.java @@ -5,11 +5,12 @@ import static graphql.Assert.assertNotNull; -public class GraphQLList implements GraphQLType, GraphQLInputType, GraphQLOutputType, GraphQLModifiedType, GraphQLNullableType { +public class GraphQLList extends AbstractGraphQLType implements GraphQLInputType, GraphQLOutputType, GraphQLModifiedType, GraphQLNullableType { private GraphQLType wrappedType; public GraphQLList(GraphQLType wrappedType) { + super(""); assertNotNull(wrappedType, "wrappedType can't be null"); this.wrappedType = wrappedType; } @@ -39,8 +40,4 @@ public int hashCode() { return wrappedType != null ? wrappedType.hashCode() : 0; } - @Override - public String getName() { - return null; - } } diff --git a/src/main/java/graphql/schema/GraphQLNonNull.java b/src/main/java/graphql/schema/GraphQLNonNull.java index 141e24d29f..85a0d695c6 100644 --- a/src/main/java/graphql/schema/GraphQLNonNull.java +++ b/src/main/java/graphql/schema/GraphQLNonNull.java @@ -5,11 +5,12 @@ import static graphql.Assert.assertNotNull; -public class GraphQLNonNull implements GraphQLType, GraphQLInputType, GraphQLOutputType, GraphQLModifiedType { +public class GraphQLNonNull extends AbstractGraphQLType implements GraphQLInputType, GraphQLOutputType, GraphQLModifiedType { private GraphQLType wrappedType; public GraphQLNonNull(GraphQLType wrappedType) { + super(""); assertNotNull(wrappedType, "wrappedType can't be null"); this.wrappedType = wrappedType; } diff --git a/src/main/java/graphql/schema/GraphQLObjectType.java b/src/main/java/graphql/schema/GraphQLObjectType.java index a7890af6cc..e7802cf867 100644 --- a/src/main/java/graphql/schema/GraphQLObjectType.java +++ b/src/main/java/graphql/schema/GraphQLObjectType.java @@ -8,18 +8,16 @@ import static graphql.Assert.assertNotNull; -public class GraphQLObjectType implements GraphQLType, GraphQLOutputType, GraphQLFieldsContainer, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { +public class GraphQLObjectType extends AbstractGraphQLType implements GraphQLOutputType, GraphQLFieldsContainer, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { - private final String name; private final String description; private final Map fieldDefinitionsByName = new LinkedHashMap<>(); private final List interfaces = new ArrayList<>(); public GraphQLObjectType(String name, String description, List fieldDefinitions, List interfaces) { - assertNotNull(name, "name can't null"); + super(name); assertNotNull(fieldDefinitions, "fieldDefinitions can't null"); assertNotNull(interfaces, "interfaces can't null"); - this.name = name; this.description = description; this.interfaces.addAll(interfaces); buildDefinitionMap(fieldDefinitions); @@ -50,16 +48,10 @@ public String getDescription() { return description; } - - public String getName() { - return name; - } - - @Override public String toString() { return "GraphQLObjectType{" + - "name='" + name + '\'' + + "name='" + getName() + '\'' + ", description='" + description + '\'' + ", fieldDefinitionsByName=" + fieldDefinitionsByName + ", interfaces=" + interfaces + diff --git a/src/main/java/graphql/schema/GraphQLScalarType.java b/src/main/java/graphql/schema/GraphQLScalarType.java index 0e2ccead8d..3025eb4fd5 100644 --- a/src/main/java/graphql/schema/GraphQLScalarType.java +++ b/src/main/java/graphql/schema/GraphQLScalarType.java @@ -3,25 +3,19 @@ import static graphql.Assert.assertNotNull; -public class GraphQLScalarType implements GraphQLType, GraphQLInputType, GraphQLOutputType, GraphQLUnmodifiedType,GraphQLNullableType { +public class GraphQLScalarType extends AbstractGraphQLType implements GraphQLInputType, GraphQLOutputType, GraphQLUnmodifiedType,GraphQLNullableType { - private final String name; private final String description; private final Coercing coercing; public GraphQLScalarType(String name, String description, Coercing coercing) { - assertNotNull(name, "name can't be null"); + super(name); assertNotNull(coercing, "coercing can't be null"); - this.name = name; this.description = description; this.coercing = coercing; } - public String getName() { - return name; - } - public String getDescription() { return description; @@ -35,7 +29,7 @@ public Coercing getCoercing() { @Override public String toString() { return "GraphQLScalarType{" + - "name='" + name + '\'' + + "name='" + getName() + '\'' + ", description='" + description + '\'' + ", coercing=" + coercing + '}'; diff --git a/src/main/java/graphql/schema/GraphQLTypeReference.java b/src/main/java/graphql/schema/GraphQLTypeReference.java index 103e326f26..ac123e0869 100644 --- a/src/main/java/graphql/schema/GraphQLTypeReference.java +++ b/src/main/java/graphql/schema/GraphQLTypeReference.java @@ -1,22 +1,13 @@ package graphql.schema; -import static graphql.Assert.assertNotNull; - /** * A special type to allow a object/interface types to reference itself. It's replaced with the real type * object when the schema is build. */ -public class GraphQLTypeReference implements GraphQLType, GraphQLOutputType { - - private final String name; +public class GraphQLTypeReference extends AbstractGraphQLType implements GraphQLOutputType { public GraphQLTypeReference(String name) { - assertNotNull(name, "name can't be null"); - this.name = name; - } - - public String getName() { - return name; + super(name); } } diff --git a/src/main/java/graphql/schema/GraphQLUnionType.java b/src/main/java/graphql/schema/GraphQLUnionType.java index 710041e600..a9f6aa32d0 100644 --- a/src/main/java/graphql/schema/GraphQLUnionType.java +++ b/src/main/java/graphql/schema/GraphQLUnionType.java @@ -6,19 +6,17 @@ import static graphql.Assert.assertNotNull; -public class GraphQLUnionType implements GraphQLType, GraphQLOutputType, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { +public class GraphQLUnionType extends AbstractGraphQLType implements GraphQLOutputType, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { - private final String name; private final String description; private List types = new ArrayList<>(); private final TypeResolver typeResolver; public GraphQLUnionType(String name, String description, List types, TypeResolver typeResolver) { - assertNotNull(name, "name can't be null"); + super(name); assertNotNull(types, "types can't be null"); assertNotNull(typeResolver, "typeResolver can't be null"); - this.name = name; this.description = description; this.types.addAll(types); this.typeResolver = typeResolver; @@ -33,11 +31,6 @@ public TypeResolver getTypeResolver() { return typeResolver; } - @Override - public String getName() { - return name; - } - public String getDescription() { return description; } From 05da528ffaa8cfa34fc438dc3149091633fdddcf Mon Sep 17 00:00:00 2001 From: Kay Roepke Date: Tue, 22 Sep 2015 11:25:04 +0200 Subject: [PATCH 2/2] remove abstract graphql type again - push getName() implementation and property down - modified types return null for getName - equals/hashcode pushed down as well, modified types delegate to wrappedType --- .../graphql/schema/AbstractGraphQLType.java | 32 ------------------- .../java/graphql/schema/GraphQLEnumType.java | 27 ++++++++++++++-- .../schema/GraphQLInputObjectType.java | 28 +++++++++++++--- .../graphql/schema/GraphQLInterfaceType.java | 26 +++++++++++++-- src/main/java/graphql/schema/GraphQLList.java | 6 ++-- .../java/graphql/schema/GraphQLNonNull.java | 3 +- .../graphql/schema/GraphQLObjectType.java | 26 +++++++++++++-- .../graphql/schema/GraphQLScalarType.java | 27 ++++++++++++++-- .../graphql/schema/GraphQLTypeReference.java | 29 +++++++++++++++-- .../java/graphql/schema/GraphQLUnionType.java | 26 +++++++++++++-- 10 files changed, 176 insertions(+), 54 deletions(-) delete mode 100644 src/main/java/graphql/schema/AbstractGraphQLType.java diff --git a/src/main/java/graphql/schema/AbstractGraphQLType.java b/src/main/java/graphql/schema/AbstractGraphQLType.java deleted file mode 100644 index b4dc1d8c01..0000000000 --- a/src/main/java/graphql/schema/AbstractGraphQLType.java +++ /dev/null @@ -1,32 +0,0 @@ -package graphql.schema; - -import static graphql.Assert.assertNotNull; - -public class AbstractGraphQLType implements GraphQLType { - private final String name; - - public AbstractGraphQLType(String name) { - assertNotNull(name, "name can't null"); - this.name = name; - } - - public String getName() { - return name.equals("") ? null : name; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - AbstractGraphQLType that = (AbstractGraphQLType) o; - - return getName().equals(that.getName()); - - } - - @Override - public int hashCode() { - return name.hashCode(); - } -} diff --git a/src/main/java/graphql/schema/GraphQLEnumType.java b/src/main/java/graphql/schema/GraphQLEnumType.java index ca4fa83bef..9a1cb8abdc 100644 --- a/src/main/java/graphql/schema/GraphQLEnumType.java +++ b/src/main/java/graphql/schema/GraphQLEnumType.java @@ -11,8 +11,9 @@ import static graphql.Assert.assertNotNull; -public class GraphQLEnumType extends AbstractGraphQLType implements GraphQLType, GraphQLInputType, GraphQLOutputType, GraphQLUnmodifiedType { +public class GraphQLEnumType implements GraphQLType, GraphQLInputType, GraphQLOutputType, GraphQLUnmodifiedType { + private final String name; private final String description; private final Map valueDefinitionMap = new LinkedHashMap<>(); @@ -45,8 +46,8 @@ public List getValues() { public GraphQLEnumType(String name, String description, List values) { - super(name); - assertNotNull(name, "name can't be null"); + assertNotNull(name, "name can't null"); + this.name = name; this.description = description; buildMap(values); } @@ -70,6 +71,26 @@ public static Builder newEnum() { return new Builder(); } + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GraphQLType that = (GraphQLType) o; + + return getName().equals(that.getName()); + + } + + @Override + public int hashCode() { + return name.hashCode(); + } + public static class Builder { private String name; diff --git a/src/main/java/graphql/schema/GraphQLInputObjectType.java b/src/main/java/graphql/schema/GraphQLInputObjectType.java index 33debc7b4f..9f35b3342b 100644 --- a/src/main/java/graphql/schema/GraphQLInputObjectType.java +++ b/src/main/java/graphql/schema/GraphQLInputObjectType.java @@ -8,16 +8,16 @@ import static graphql.Assert.assertNotNull; -public class GraphQLInputObjectType extends AbstractGraphQLType implements GraphQLInputType, GraphQLUnmodifiedType, GraphQLNullableType { +public class GraphQLInputObjectType implements GraphQLInputType, GraphQLUnmodifiedType, GraphQLNullableType { + private final String name; private final String description; - - private final Map fieldMap = new LinkedHashMap<>(); public GraphQLInputObjectType(String name, String description, List fields) { - super(name); + assertNotNull(name, "name can't null"); assertNotNull(fields, "fields can't be null"); + this.name = name; this.description = description; buildMap(fields); } @@ -44,6 +44,26 @@ public static Builder newInputObject() { return new Builder(); } + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GraphQLType that = (GraphQLType) o; + + return getName().equals(that.getName()); + + } + + @Override + public int hashCode() { + return name.hashCode(); + } + public static class Builder { private String name; private String description; diff --git a/src/main/java/graphql/schema/GraphQLInterfaceType.java b/src/main/java/graphql/schema/GraphQLInterfaceType.java index 1e8979ee03..1119da467b 100644 --- a/src/main/java/graphql/schema/GraphQLInterfaceType.java +++ b/src/main/java/graphql/schema/GraphQLInterfaceType.java @@ -8,16 +8,18 @@ import static graphql.Assert.assertNotNull; -public class GraphQLInterfaceType extends AbstractGraphQLType implements GraphQLOutputType, GraphQLFieldsContainer, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { +public class GraphQLInterfaceType implements GraphQLOutputType, GraphQLFieldsContainer, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { + private final String name; private final String description; private final Map fieldDefinitionsByName = new LinkedHashMap<>(); private final TypeResolver typeResolver; public GraphQLInterfaceType(String name, String description, List fieldDefinitions, TypeResolver typeResolver) { - super(name); + assertNotNull(name, "name can't null"); assertNotNull(typeResolver, "typeResolver can't null"); assertNotNull(fieldDefinitions, "fieldDefinitions can't null"); + this.name = name; this.description = description; buildDefinitionMap(fieldDefinitions); this.typeResolver = typeResolver; @@ -60,6 +62,26 @@ public static Builder newInterface() { return new Builder(); } + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GraphQLType that = (GraphQLType) o; + + return getName().equals(that.getName()); + + } + + @Override + public int hashCode() { + return name.hashCode(); + } + public static class Builder { private String name; diff --git a/src/main/java/graphql/schema/GraphQLList.java b/src/main/java/graphql/schema/GraphQLList.java index e7c010531f..8e8b185c88 100644 --- a/src/main/java/graphql/schema/GraphQLList.java +++ b/src/main/java/graphql/schema/GraphQLList.java @@ -5,12 +5,11 @@ import static graphql.Assert.assertNotNull; -public class GraphQLList extends AbstractGraphQLType implements GraphQLInputType, GraphQLOutputType, GraphQLModifiedType, GraphQLNullableType { +public class GraphQLList implements GraphQLInputType, GraphQLOutputType, GraphQLModifiedType, GraphQLNullableType { private GraphQLType wrappedType; public GraphQLList(GraphQLType wrappedType) { - super(""); assertNotNull(wrappedType, "wrappedType can't be null"); this.wrappedType = wrappedType; } @@ -40,4 +39,7 @@ public int hashCode() { return wrappedType != null ? wrappedType.hashCode() : 0; } + public String getName() { + return null; + } } diff --git a/src/main/java/graphql/schema/GraphQLNonNull.java b/src/main/java/graphql/schema/GraphQLNonNull.java index 85a0d695c6..fc3fe7cf78 100644 --- a/src/main/java/graphql/schema/GraphQLNonNull.java +++ b/src/main/java/graphql/schema/GraphQLNonNull.java @@ -5,12 +5,11 @@ import static graphql.Assert.assertNotNull; -public class GraphQLNonNull extends AbstractGraphQLType implements GraphQLInputType, GraphQLOutputType, GraphQLModifiedType { +public class GraphQLNonNull implements GraphQLInputType, GraphQLOutputType, GraphQLModifiedType { private GraphQLType wrappedType; public GraphQLNonNull(GraphQLType wrappedType) { - super(""); assertNotNull(wrappedType, "wrappedType can't be null"); this.wrappedType = wrappedType; } diff --git a/src/main/java/graphql/schema/GraphQLObjectType.java b/src/main/java/graphql/schema/GraphQLObjectType.java index e7802cf867..00a4ae16d0 100644 --- a/src/main/java/graphql/schema/GraphQLObjectType.java +++ b/src/main/java/graphql/schema/GraphQLObjectType.java @@ -8,16 +8,18 @@ import static graphql.Assert.assertNotNull; -public class GraphQLObjectType extends AbstractGraphQLType implements GraphQLOutputType, GraphQLFieldsContainer, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { +public class GraphQLObjectType implements GraphQLOutputType, GraphQLFieldsContainer, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { + private final String name; private final String description; private final Map fieldDefinitionsByName = new LinkedHashMap<>(); private final List interfaces = new ArrayList<>(); public GraphQLObjectType(String name, String description, List fieldDefinitions, List interfaces) { - super(name); + assertNotNull(name, "name can't null"); assertNotNull(fieldDefinitions, "fieldDefinitions can't null"); assertNotNull(interfaces, "interfaces can't null"); + this.name = name; this.description = description; this.interfaces.addAll(interfaces); buildDefinitionMap(fieldDefinitions); @@ -62,6 +64,26 @@ public static Builder newObject() { return new Builder(); } + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GraphQLType that = (GraphQLType) o; + + return getName().equals(that.getName()); + + } + + @Override + public int hashCode() { + return name.hashCode(); + } + public static class Builder { private String name; diff --git a/src/main/java/graphql/schema/GraphQLScalarType.java b/src/main/java/graphql/schema/GraphQLScalarType.java index 3025eb4fd5..5eacf59536 100644 --- a/src/main/java/graphql/schema/GraphQLScalarType.java +++ b/src/main/java/graphql/schema/GraphQLScalarType.java @@ -3,15 +3,16 @@ import static graphql.Assert.assertNotNull; -public class GraphQLScalarType extends AbstractGraphQLType implements GraphQLInputType, GraphQLOutputType, GraphQLUnmodifiedType,GraphQLNullableType { +public class GraphQLScalarType implements GraphQLInputType, GraphQLOutputType, GraphQLUnmodifiedType,GraphQLNullableType { + private final String name; private final String description; private final Coercing coercing; - public GraphQLScalarType(String name, String description, Coercing coercing) { - super(name); + assertNotNull(name, "name can't null"); assertNotNull(coercing, "coercing can't be null"); + this.name = name; this.description = description; this.coercing = coercing; } @@ -34,4 +35,24 @@ public String toString() { ", coercing=" + coercing + '}'; } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GraphQLType that = (GraphQLType) o; + + return getName().equals(that.getName()); + + } + + @Override + public int hashCode() { + return name.hashCode(); + } } diff --git a/src/main/java/graphql/schema/GraphQLTypeReference.java b/src/main/java/graphql/schema/GraphQLTypeReference.java index ac123e0869..0b2c01d1b6 100644 --- a/src/main/java/graphql/schema/GraphQLTypeReference.java +++ b/src/main/java/graphql/schema/GraphQLTypeReference.java @@ -1,13 +1,38 @@ package graphql.schema; +import static graphql.Assert.assertNotNull; + /** * A special type to allow a object/interface types to reference itself. It's replaced with the real type * object when the schema is build. */ -public class GraphQLTypeReference extends AbstractGraphQLType implements GraphQLOutputType { +public class GraphQLTypeReference implements GraphQLOutputType { + + private final String name; public GraphQLTypeReference(String name) { - super(name); + assertNotNull(name, "name can't null"); + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GraphQLType that = (GraphQLType) o; + + return getName().equals(that.getName()); + + } + + @Override + public int hashCode() { + return name.hashCode(); } } diff --git a/src/main/java/graphql/schema/GraphQLUnionType.java b/src/main/java/graphql/schema/GraphQLUnionType.java index a9f6aa32d0..ac67098e7b 100644 --- a/src/main/java/graphql/schema/GraphQLUnionType.java +++ b/src/main/java/graphql/schema/GraphQLUnionType.java @@ -6,17 +6,19 @@ import static graphql.Assert.assertNotNull; -public class GraphQLUnionType extends AbstractGraphQLType implements GraphQLOutputType, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { +public class GraphQLUnionType implements GraphQLOutputType, GraphQLCompositeType, GraphQLUnmodifiedType, GraphQLNullableType { + private final String name; private final String description; private List types = new ArrayList<>(); private final TypeResolver typeResolver; public GraphQLUnionType(String name, String description, List types, TypeResolver typeResolver) { - super(name); + assertNotNull(name, "name can't null"); assertNotNull(types, "types can't be null"); assertNotNull(typeResolver, "typeResolver can't be null"); + this.name = name; this.description = description; this.types.addAll(types); this.typeResolver = typeResolver; @@ -39,6 +41,26 @@ public static Builder newUnionType() { return new Builder(); } + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + GraphQLType that = (GraphQLType) o; + + return getName().equals(that.getName()); + + } + + @Override + public int hashCode() { + return name.hashCode(); + } + public static class Builder { private String name; private String description;