Skip to content

Commit

Permalink
Make GraphQLNamedType conform to Hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
lukel97 committed Jun 9, 2022
1 parent 3933850 commit edcfcba
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Sources/GraphQL/Type/Definition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import NIO
/**
* These are all of the possible kinds of types.
*/
public protocol GraphQLType : CustomDebugStringConvertible, Encodable, KeySubscriptable, AnyObject, Equatable {}
public protocol GraphQLType : CustomDebugStringConvertible, Encodable, KeySubscriptable, AnyObject {}
extension GraphQLScalarType : GraphQLType {}
extension GraphQLObjectType : GraphQLType {}
extension GraphQLInterfaceType : GraphQLType {}
Expand All @@ -14,12 +14,6 @@ extension GraphQLInputObjectType : GraphQLType {}
extension GraphQLList : GraphQLType {}
extension GraphQLNonNull : GraphQLType {}

extension GraphQLType {
public static func == (lhs: Self, rhs: Self) -> Bool {
ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
}
}

/**
* These types may be used as input types for arguments and directives.
*/
Expand Down Expand Up @@ -120,10 +114,20 @@ func getNullableType(type: (any GraphQLType)?) -> (any GraphQLNullableType)? {
/**
* These named types do not include modifiers like List or NonNull.
*/
public protocol GraphQLNamedType : GraphQLNullableType {
public protocol GraphQLNamedType : GraphQLNullableType, Hashable {
var name: String { get }
}

extension GraphQLNamedType {
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.name == rhs.name
}

public func hash(into hasher: inout Hasher) {
name.hash(into: &hasher)
}
}

extension GraphQLScalarType : GraphQLNamedType {}
extension GraphQLObjectType : GraphQLNamedType {}
extension GraphQLInterfaceType : GraphQLNamedType {}
Expand Down

0 comments on commit edcfcba

Please sign in to comment.