From 986e46f46daaa187de66a8194ee3a2614ca4538a Mon Sep 17 00:00:00 2001 From: Alexander Steiner Date: Fri, 21 Feb 2020 19:32:40 +0100 Subject: [PATCH] Add enum type extension to infer cases via CaseIterable from an enum --- Sources/GraphQLKit/Graphiti+Enum.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Sources/GraphQLKit/Graphiti+Enum.swift diff --git a/Sources/GraphQLKit/Graphiti+Enum.swift b/Sources/GraphQLKit/Graphiti+Enum.swift new file mode 100644 index 0000000..5aeeb12 --- /dev/null +++ b/Sources/GraphQLKit/Graphiti+Enum.swift @@ -0,0 +1,13 @@ +import Graphiti +import Vapor + +extension Enum where EnumType: CaseIterable { + // Initialize an enum type from a `CaseIterable` enum. + public convenience init( + _ type: EnumType.Type, + name: String? = nil + ) { + self.init(type, name: name, EnumType.allCases.map({ Value($0) })) + } +} +