Description
When selecting fragments on a union, Morpheus inserts a __typename field in the answer. If I have the following schema:
union Test = Foo | Bar
type Foo {
foo: Int!
}
type Bar {
bar: Int!
}
type Query {
getFooOrBar(id: Int!): Test
}
and I send the following query:
query {
getFooOrBar(id: 1) {
... on Foo {
foo
}
... on Bar {
bar
}
}
}
I am expecting to receive (in the case of Foo):
data:
getFooOrBar:
foo: 1
but instead I receive:
data:
getFooOrBar:
__typename: Foo
foo: 1
Minimal program
import Data.Aeson (encode)
import Data.ByteString.Lazy as B (putStr)
import Data.Morpheus.Document
import Data.Morpheus.Types
import Data.Morpheus
[gqlDocument|
union Test = Foo | Bar
type Foo {
foo: Int!
}
type Bar {
bar: Int!
}
type Query {
getFooOrBar(id: Int!): Test
}
|]
queryRoot :: Query (Resolver QUERY () IO)
queryRoot = Query {getFooOrBar}
where
getFooOrBar (Arg i) = pure $ case i of
1 -> Just $ TestFoo $ Foo $ pure 1
2 -> Just $ TestBar $ Bar $ pure 2
_ -> Nothing
main = do
let
service :: GQLRequest -> IO GQLResponse
service = interpreter $ RootResolver queryRoot Undefined Undefined
send q = service $ GQLRequest
{ operationName = Nothing
, variables = Nothing
, query = q
}
B.putStr . encode =<< send "\
\query {\
\ getFooOrBar(id: 1) {\
\ ... on Foo {\
\ foo\
\ }\
\ ... on Bar {\
\ bar\
\ }\
\ }\
\}"
Description
When selecting fragments on a union, Morpheus inserts a
__typenamefield in the answer. If I have the following schema:and I send the following query:
I am expecting to receive (in the case of
Foo):but instead I receive:
Minimal program