Skip to content

morpheus-graphql-0.2.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@nalchevanidze nalchevanidze released this 23 Aug 21:18

[0.2.0] - 23.08.2019

thank you for contributing: @horus @ryota-ka @hovind @gvolpe

Added

  • Parser Supports GraphQL Single Line comments

  • Enhanced Subscription: mutation can trigger subscription with arguments

  • Experimental Support of Input Unions

  • GraphQL schema generating with: Data.Morpheus.Document.toGraphQLDocument

  • Generating dummy Morpheus Api from schema.gql:

    morpheus build schema/mythology.gql src/MythologyApi.hs
    

    details

  • convertToJSONName & convertToHaskellName has been extended to support all Haskell 2010 reserved identities. details

  • GraphQL Client with Template haskell QuasiQuotes (Experimental, Not fully Implemented)

    defineQuery
      [gql|
        query GetHero ($byRealm: Realm)
          {
            deity (realm:$byRealm) {
              power
              fullName
            }
          }
      |]

    will Generate:

    • response type GetHero, Deity with Lens Instances
    • input types: GetHeroArgs , Realm
    • instance for Fetch typeClass

    so that

      fetchHero :: Args GetHero -> m (Either String GetHero)
      fetchHero = fetch jsonRes args
          where
            args = GetHeroArgs {byRealm = Just Realm {owner = "Zeus", surface = Just 10}}
            jsonRes :: ByteString -> m ByteString
            jsonRes = <fetch query from server>

    resolves well typed response GetHero.

  • Ability to define GQLSchema with GraphQL syntax ,
    so that with this schema

    [gqlDocument|
      type Query {
        deity (uid: Text! ) : Deity!
      }
    
      type Deity {
        name  : Text!
        power : Text
      }
    |]
    
    rootResolver :: GQLRootResolver IO () () Query () ()
    rootResolver =
      GQLRootResolver {queryResolver = return Query {deity}, mutationResolver = pure (), subscriptionResolver = pure ()}
      where
        deity DeityArgs {uid} = pure Deity {name, power}
          where
            name _ = pure "Morpheus"
            power _ = pure (Just "Shapeshifting")

    Template Haskell Generates types: Query , Deity, DeityArgs, that can be used by rootResolver

    generated types are not compatible with Mutation, Subscription,
    they can be used only in Query, but this issue will be fixed in next release

Fixed:

  • Parser supports enums inside input Object

  • fulfilled fragment Validation (added: unusedFragment,nameConflict)

  • correct decoding of Enums with more than 3 constructor #201

  • Duplicated variable names in Http requests are validated using Aeson's jsonNoDup function. So the following request will
    result in a parsing error

    {"query":"...",
    "variables":{"email":"foo@mail.net", "email":"bar@mail.net",...}}
    

Changed

  • WebSocket subProtocol changed from graphql-subscriptions to graphql-ws

  • type familiy KIND is moved into typeClasses GQLType, so you should replace

    type instance KIND Deity = OBJECT
    
    instance GQLType Deity where
      description  = const "Custom Description for Client Defined User Type"
    
    data Deity = Deity { fullName :: Text } deriving (Generic)

    with

    instance GQLType Deity where
    type KIND Deity = OBJECT
    description = const "Custom Description for Client Defined User Type"
    
    data Deity = Deity { fullName :: Text } deriving (Generic)