Parse interface type definition

This commit is contained in:
Eugen Wissner 2020-01-11 08:32:25 +01:00
parent f4ed06741d
commit adffa185bb
4 changed files with 21 additions and 4 deletions

View File

@ -10,10 +10,10 @@ setup() {
fi fi
if [ -e "$SEMAPHORE_CACHE_DIR/graphql.cabal" ] if [ -e "$SEMAPHORE_CACHE_DIR/graphql.cabal" ]
then then
cp -a $SEMAPHORE_CACHE_DIR/graphql.cabal graphql.cabal cp -a $SEMAPHORE_CACHE_DIR/graphql.cabal graphql.cabal
fi fi
$STACK --no-terminal setup $STACK --no-terminal setup
cp -a graphql.cabal $SEMAPHORE_CACHE_DIR/graphql.cabal cp -a graphql.cabal $SEMAPHORE_CACHE_DIR/graphql.cabal
} }
setup_test() { setup_test() {

View File

@ -38,6 +38,7 @@ typeSystemDefinition = schemaDefinition
typeDefinition :: Parser TypeDefinition typeDefinition :: Parser TypeDefinition
typeDefinition = scalarTypeDefinition typeDefinition = scalarTypeDefinition
<|> objectTypeDefinition <|> objectTypeDefinition
<|> interfaceTypeDefinition
<|> unionTypeDefinition <|> unionTypeDefinition
<?> "TypeDefinition" <?> "TypeDefinition"
@ -83,6 +84,15 @@ unionMemberTypes sepBy' = UnionMemberTypes
<*> name `sepBy'` pipe <*> name `sepBy'` pipe
<?> "UnionMemberTypes" <?> "UnionMemberTypes"
interfaceTypeDefinition :: Parser TypeDefinition
interfaceTypeDefinition = InterfaceTypeDefinition
<$> description
<* symbol "interface"
<*> name
<*> opt directives
<*> braces (many fieldDefinition)
<?> "InterfaceTypeDefinition"
implementsInterfaces :: implementsInterfaces ::
Foldable t => Foldable t =>
(Parser Text -> Parser Text -> Parser (t NamedType)) -> (Parser Text -> Parser Text -> Parser (t NamedType)) ->

View File

@ -94,7 +94,7 @@ resolveFieldValue f resolveRight fld@(Field _ _ args _) = do
_ <- addErrMsg err _ <- addErrMsg err
return $ HashMap.singleton (aliasOrName fld) Aeson.Null 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) withField :: (MonadIO m, Aeson.ToJSON a)
=> CollectErrsT m a -> Field -> CollectErrsT m (HashMap Text Aeson.Value) => CollectErrsT m a -> Field -> CollectErrsT m (HashMap Text Aeson.Value)
withField v fld withField v fld

View File

@ -74,3 +74,10 @@ spec = describe "Parser" $ do
parse document "" `shouldSucceedOn` [r| parse document "" `shouldSucceedOn` [r|
union SearchResult = Photo | Person union SearchResult = Photo | Person
|] |]
it "parses minimal interface type definition" $
parse document "" `shouldSucceedOn` [r|
interface NamedEntity {
name: String
}
|]