summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2020-01-11 08:32:25 +0100
committerEugen Wissner <belka@caraus.de>2020-01-13 08:21:02 +0100
commitadffa185bb249394ef651392b41b7a20b26031cc (patch)
tree40547a4ef3fa1804924144d73dbcf9630a451b23
parentf4ed06741dedb7b19cedc09b1c47afe1f0849f24 (diff)
downloadgraphql-adffa185bb249394ef651392b41b7a20b26031cc.tar.gz
Parse interface type definition
-rwxr-xr-xsemaphoreci.sh6
-rw-r--r--src/Language/GraphQL/AST/Parser.hs10
-rw-r--r--src/Language/GraphQL/Schema.hs2
-rw-r--r--tests/Language/GraphQL/AST/ParserSpec.hs7
4 files changed, 21 insertions, 4 deletions
diff --git a/semaphoreci.sh b/semaphoreci.sh
index eb9ef38..d7c8a93 100755
--- a/semaphoreci.sh
+++ b/semaphoreci.sh
@@ -10,10 +10,10 @@ setup() {
fi
if [ -e "$SEMAPHORE_CACHE_DIR/graphql.cabal" ]
then
- cp -a $SEMAPHORE_CACHE_DIR/graphql.cabal graphql.cabal
- fi
+ cp -a $SEMAPHORE_CACHE_DIR/graphql.cabal graphql.cabal
+ fi
$STACK --no-terminal setup
- cp -a graphql.cabal $SEMAPHORE_CACHE_DIR/graphql.cabal
+ cp -a graphql.cabal $SEMAPHORE_CACHE_DIR/graphql.cabal
}
setup_test() {
diff --git a/src/Language/GraphQL/AST/Parser.hs b/src/Language/GraphQL/AST/Parser.hs
index 274045d..41748b2 100644
--- a/src/Language/GraphQL/AST/Parser.hs
+++ b/src/Language/GraphQL/AST/Parser.hs
@@ -38,6 +38,7 @@ typeSystemDefinition = schemaDefinition
typeDefinition :: Parser TypeDefinition
typeDefinition = scalarTypeDefinition
<|> objectTypeDefinition
+ <|> interfaceTypeDefinition
<|> unionTypeDefinition
<?> "TypeDefinition"
@@ -83,6 +84,15 @@ unionMemberTypes sepBy' = UnionMemberTypes
<*> name `sepBy'` pipe
<?> "UnionMemberTypes"
+interfaceTypeDefinition :: Parser TypeDefinition
+interfaceTypeDefinition = InterfaceTypeDefinition
+ <$> description
+ <* symbol "interface"
+ <*> name
+ <*> opt directives
+ <*> braces (many fieldDefinition)
+ <?> "InterfaceTypeDefinition"
+
implementsInterfaces ::
Foldable t =>
(Parser Text -> Parser Text -> Parser (t NamedType)) ->
diff --git a/src/Language/GraphQL/Schema.hs b/src/Language/GraphQL/Schema.hs
index 8bdf605..661e452 100644
--- a/src/Language/GraphQL/Schema.hs
+++ b/src/Language/GraphQL/Schema.hs
@@ -94,7 +94,7 @@ resolveFieldValue f resolveRight fld@(Field _ _ args _) = do
_ <- addErrMsg err
return $ HashMap.singleton (aliasOrName fld) Aeson.Null
--- | Helper function to facilitate 'Argument' handling.
+-- | Helper function to facilitate error handling and result emitting.
withField :: (MonadIO m, Aeson.ToJSON a)
=> CollectErrsT m a -> Field -> CollectErrsT m (HashMap Text Aeson.Value)
withField v fld
diff --git a/tests/Language/GraphQL/AST/ParserSpec.hs b/tests/Language/GraphQL/AST/ParserSpec.hs
index e1b48d8..efb5b63 100644
--- a/tests/Language/GraphQL/AST/ParserSpec.hs
+++ b/tests/Language/GraphQL/AST/ParserSpec.hs
@@ -74,3 +74,10 @@ spec = describe "Parser" $ do
parse document "" `shouldSucceedOn` [r|
union SearchResult = Photo | Person
|]
+
+ it "parses minimal interface type definition" $
+ parse document "" `shouldSucceedOn` [r|
+ interface NamedEntity {
+ name: String
+ }
+ |]