forked from OSS/graphql
		
	Encode unions
This commit is contained in:
		| @@ -128,6 +128,13 @@ typeDefinition formatter = \case | |||||||
|         <> optempty (directives formatter) directives' |         <> optempty (directives formatter) directives' | ||||||
|         <> eitherFormat formatter " " "" |         <> eitherFormat formatter " " "" | ||||||
|         <> bracesList formatter (fieldDefinition nextFormatter) fields' |         <> bracesList formatter (fieldDefinition nextFormatter) fields' | ||||||
|  |     Full.UnionTypeDefinition description' name' directives' members' | ||||||
|  |         -> optempty (description formatter) description' | ||||||
|  |         <> "union " | ||||||
|  |         <> Lazy.Text.fromStrict name' | ||||||
|  |         <> optempty (directives formatter) directives' | ||||||
|  |         <> eitherFormat formatter " " "" | ||||||
|  |         <> unionMemberTypes formatter members' | ||||||
|     _typeDefinition' -> "" -- TODO: Types missing. |     _typeDefinition' -> "" -- TODO: Types missing. | ||||||
|   where |   where | ||||||
|     nextFormatter = incrementIndent formatter |     nextFormatter = incrementIndent formatter | ||||||
| @@ -136,10 +143,23 @@ implementsInterfaces :: Foldable t => Full.ImplementsInterfaces t -> Lazy.Text | |||||||
| implementsInterfaces (Full.ImplementsInterfaces interfaces) | implementsInterfaces (Full.ImplementsInterfaces interfaces) | ||||||
|     | null interfaces = mempty |     | null interfaces = mempty | ||||||
|     | otherwise = Lazy.Text.fromStrict |     | otherwise = Lazy.Text.fromStrict | ||||||
|         $ Text.append "implements" |         $ Text.append "implements " | ||||||
|         $ Text.intercalate " & " |         $ Text.intercalate " & " | ||||||
|         $ toList interfaces |         $ toList interfaces | ||||||
|  |  | ||||||
|  | unionMemberTypes :: Foldable t => Formatter -> Full.UnionMemberTypes t -> Lazy.Text | ||||||
|  | unionMemberTypes formatter (Full.UnionMemberTypes memberTypes) | ||||||
|  |     | null memberTypes = mempty | ||||||
|  |     | Minified <- formatter = Lazy.Text.fromStrict | ||||||
|  |         $ Text.append "= " | ||||||
|  |         $ Text.intercalate " | " | ||||||
|  |         $ toList memberTypes | ||||||
|  |     | Pretty _ <- formatter | ||||||
|  |         = Lazy.Text.append "=" | ||||||
|  |         $ Lazy.Text.concat | ||||||
|  |         $ (("\n" <> indentSymbol <> "| ") <>) . Lazy.Text.fromStrict | ||||||
|  |         <$> toList memberTypes | ||||||
|  |  | ||||||
| description :: Formatter -> Full.Description -> Lazy.Text.Text | description :: Formatter -> Full.Description -> Lazy.Text.Text | ||||||
| description _formatter (Full.Description Nothing) = "" | description _formatter (Full.Description Nothing) = "" | ||||||
| description formatter (Full.Description (Just description')) = | description formatter (Full.Description (Just description')) = | ||||||
|   | |||||||
| @@ -217,3 +217,15 @@ spec = do | |||||||
|                 |] |                 |] | ||||||
|                 actual = typeSystemDefinition pretty definition' |                 actual = typeSystemDefinition pretty definition' | ||||||
|              in actual `shouldBe` expected |              in actual `shouldBe` expected | ||||||
|  |  | ||||||
|  |         it "encodes an enum definition" $ | ||||||
|  |             let definition' = Full.TypeDefinition | ||||||
|  |                     $ Full.UnionTypeDefinition mempty "SearchResult" mempty | ||||||
|  |                     $ Full.UnionMemberTypes ["Photo", "Person"] | ||||||
|  |                 expected = [gql| | ||||||
|  |                   union SearchResult = | ||||||
|  |                     | Photo | ||||||
|  |                     | Person | ||||||
|  |                 |] | ||||||
|  |                 actual = typeSystemDefinition pretty definition' | ||||||
|  |              in actual `shouldBe` expected | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user