forked from OSS/graphql
Compare commits
1 Commits
97d304d283
...
feature/rn
Author | SHA1 | Date | |
---|---|---|---|
1b3727bc05
|
@ -85,6 +85,7 @@ test-suite graphql-test
|
|||||||
Language.GraphQL.Execute.CoerceSpec
|
Language.GraphQL.Execute.CoerceSpec
|
||||||
Language.GraphQL.Execute.OrderedMapSpec
|
Language.GraphQL.Execute.OrderedMapSpec
|
||||||
Language.GraphQL.ExecuteSpec
|
Language.GraphQL.ExecuteSpec
|
||||||
|
Language.GraphQL.THSpec
|
||||||
Language.GraphQL.Type.OutSpec
|
Language.GraphQL.Type.OutSpec
|
||||||
Language.GraphQL.Validate.RulesSpec
|
Language.GraphQL.Validate.RulesSpec
|
||||||
Schemas.HeroSchema
|
Schemas.HeroSchema
|
||||||
@ -106,6 +107,4 @@ test-suite graphql-test
|
|||||||
unordered-containers,
|
unordered-containers,
|
||||||
containers,
|
containers,
|
||||||
vector
|
vector
|
||||||
build-tool-depends:
|
|
||||||
hspec-discover:hspec-discover
|
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
@ -556,24 +556,33 @@ coerceArgumentValues argumentDefinitions argumentValues =
|
|||||||
$ Just inputValue
|
$ Just inputValue
|
||||||
| otherwise -> throwM
|
| otherwise -> throwM
|
||||||
$ InputCoercionException (Text.unpack argumentName) variableType Nothing
|
$ InputCoercionException (Text.unpack argumentName) variableType Nothing
|
||||||
|
|
||||||
matchFieldValues' = matchFieldValues coerceArgumentValue
|
matchFieldValues' = matchFieldValues coerceArgumentValue
|
||||||
$ Full.node <$> argumentValues
|
$ Full.node <$> argumentValues
|
||||||
|
coerceArgumentValue inputType (Transform.Int integer) =
|
||||||
coerceArgumentValue inputType transform =
|
coerceInputLiteral inputType (Type.Int integer)
|
||||||
coerceInputLiteral inputType $ extractArgumentValue transform
|
coerceArgumentValue inputType (Transform.Boolean boolean) =
|
||||||
|
coerceInputLiteral inputType (Type.Boolean boolean)
|
||||||
extractArgumentValue (Transform.Int integer) = Type.Int integer
|
coerceArgumentValue inputType (Transform.String string) =
|
||||||
extractArgumentValue (Transform.Boolean boolean) = Type.Boolean boolean
|
coerceInputLiteral inputType (Type.String string)
|
||||||
extractArgumentValue (Transform.String string) = Type.String string
|
coerceArgumentValue inputType (Transform.Float float) =
|
||||||
extractArgumentValue (Transform.Float float) = Type.Float float
|
coerceInputLiteral inputType (Type.Float float)
|
||||||
extractArgumentValue (Transform.Enum enum) = Type.Enum enum
|
coerceArgumentValue inputType (Transform.Enum enum) =
|
||||||
extractArgumentValue Transform.Null = Type.Null
|
coerceInputLiteral inputType (Type.Enum enum)
|
||||||
extractArgumentValue (Transform.List list) =
|
coerceArgumentValue inputType Transform.Null
|
||||||
Type.List $ extractArgumentValue <$> list
|
| In.isNonNullType inputType = Nothing
|
||||||
extractArgumentValue (Transform.Object object) =
|
| otherwise = coerceInputLiteral inputType Type.Null
|
||||||
Type.Object $ extractArgumentValue <$> object
|
coerceArgumentValue (In.ListBaseType inputType) (Transform.List list) =
|
||||||
extractArgumentValue (Transform.Variable variable) = variable
|
let coerceItem = coerceArgumentValue inputType
|
||||||
|
in Type.List <$> traverse coerceItem list
|
||||||
|
coerceArgumentValue (In.InputObjectBaseType inputType) (Transform.Object object)
|
||||||
|
| In.InputObjectType _ _ inputFields <- inputType =
|
||||||
|
let go = forEachField object
|
||||||
|
resultMap = HashMap.foldrWithKey go (pure mempty) inputFields
|
||||||
|
in Type.Object <$> resultMap
|
||||||
|
coerceArgumentValue _ (Transform.Variable variable) = pure variable
|
||||||
|
coerceArgumentValue _ _ = Nothing
|
||||||
|
forEachField object variableName (In.InputField _ variableType defaultValue) =
|
||||||
|
matchFieldValues coerceArgumentValue object variableName variableType defaultValue
|
||||||
|
|
||||||
collectFields :: Monad m
|
collectFields :: Monad m
|
||||||
=> Out.ObjectType m
|
=> Out.ObjectType m
|
||||||
|
@ -12,17 +12,26 @@ import Language.Haskell.TH (Exp(..), Lit(..))
|
|||||||
|
|
||||||
stripIndentation :: String -> String
|
stripIndentation :: String -> String
|
||||||
stripIndentation code = reverse
|
stripIndentation code = reverse
|
||||||
$ dropNewlines
|
$ dropWhile isLineBreak
|
||||||
$ reverse
|
$ reverse
|
||||||
$ unlines
|
$ unlines
|
||||||
$ indent spaces <$> lines withoutLeadingNewlines
|
$ indent spaces <$> lines' withoutLeadingNewlines
|
||||||
where
|
where
|
||||||
indent 0 xs = xs
|
indent 0 xs = xs
|
||||||
indent count (' ' : xs) = indent (count - 1) xs
|
indent count (' ' : xs) = indent (count - 1) xs
|
||||||
indent _ xs = xs
|
indent _ xs = xs
|
||||||
withoutLeadingNewlines = dropNewlines code
|
withoutLeadingNewlines = dropWhile isLineBreak code
|
||||||
dropNewlines = dropWhile $ flip any ['\n', '\r'] . (==)
|
|
||||||
spaces = length $ takeWhile (== ' ') withoutLeadingNewlines
|
spaces = length $ takeWhile (== ' ') withoutLeadingNewlines
|
||||||
|
lines' "" = []
|
||||||
|
lines' string =
|
||||||
|
let (line, rest) = break isLineBreak string
|
||||||
|
reminder =
|
||||||
|
case rest of
|
||||||
|
[] -> []
|
||||||
|
'\r' : '\n' : strippedString -> lines strippedString
|
||||||
|
_ : strippedString -> lines strippedString
|
||||||
|
in line : reminder
|
||||||
|
isLineBreak = flip any ['\n', '\r'] . (==)
|
||||||
|
|
||||||
-- | Removes leading and trailing newlines. Indentation of the first line is
|
-- | Removes leading and trailing newlines. Indentation of the first line is
|
||||||
-- removed from each line of the string.
|
-- removed from each line of the string.
|
||||||
|
23
tests/Language/GraphQL/THSpec.hs
Normal file
23
tests/Language/GraphQL/THSpec.hs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
||||||
|
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||||
|
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||||
|
|
||||||
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
|
||||||
|
module Language.GraphQL.THSpec
|
||||||
|
( spec
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Language.GraphQL.TH (gql)
|
||||||
|
import Test.Hspec (Spec, describe, it, shouldBe)
|
||||||
|
|
||||||
|
spec :: Spec
|
||||||
|
spec =
|
||||||
|
describe "gql" $
|
||||||
|
it "replaces CRNL with NL" $
|
||||||
|
let expected = "line1\nline2"
|
||||||
|
actual = [gql|
|
||||||
|
line1
|
||||||
|
line2
|
||||||
|
|]
|
||||||
|
in actual `shouldBe` expected
|
Reference in New Issue
Block a user