morpheus-graphql v0.17.0 Release Notes

  • ๐Ÿ†• new features

    • ๐Ÿ‘ (issue #543 & #558): GQLTypeOptions supports new option typeNameModifier. Before the schema failed if you wanted to use the same type for input and output, and the user had no control over the eventual GraphQL type name of the generated schema. Now with this option you can provide a function of type Bool -> String -> String that generates a custom GraphQL type name. The first argument is a Bool that is True if the type is an input, and False otherwise. The second argument is a String representing the initial, auto-generated GraphQL type name. The function returns the desired type name. thanks @nalchevanidze & @bradsherman

    e.g this schema will not fail. morpheus will generate types: Deity and InputDeity

      data Deity = Deity
      { name :: Text,
        age :: Int
      }
      deriving (Show, Generic)
    
      deityTypeNameModifier isInput original
        | isInput = "Input" ++ original
        | otherwise = original
    
      instance GQLType Deity where
        typeOptions _ opt = opt {typeNameModifier = deityTypeNameModifier}
    
      newtype DeityArgs = DeityArgs
        { input :: Deity
        }
        deriving (Show, Generic, GQLType)
    
      newtype Query (m :: * -> *) = Query
        { deity :: DeityArgs -> m Deity
        }
        deriving (Generic, GQLType)
    
    • ๐Ÿ”ฆ exposed EncodeWrapper and DecodeWrapper type-classes.

    ๐Ÿ’ฅ Breaking Changes

    • Map k v is now represented as just [Pair k v]
    • GQLScalar was replaced with EncodeScalar and DecodeScalar type-classes.
    • Exclusive input objects: Sum types used as input types are represented as input objects, where only one field must have a value. Namespaced constructors (i.e., where referenced type name concatenated with union type name is equal to constructor name) are unpacked. Furthermore, empty constructors are represented as fields with the unit type.

    for example:

          data Device
            | DevicePC PC
            | Laptops { macAdress :: ID }
            | Smartphone
    

    this type will generate the following SDL:

      enum Unit {
        Unit
      }
    
      input Laptop {
        macAdress: ID
      }
    
      input Device {
        PC: PC
        Laptops: Laptops
        Smartphone: Unit
      }
    
    • For each nullary constructor will be defined GQL object type with a single field _: Unit (since GraphQL does not allow empty objects).

    for example:

      data Person = Client { name :: Text } | Accountant | Developer
    

    this type will generate the following SDL:

      enum Unit {
        Unit
      }
    
      type Student {
        name: String!
      }
    
      type Accountant {
        _: Unit!
      }
    
      type Developer {
        _: Unit!
      }
    
      union Person = Client | Accountant | Developer
    
    • ๐Ÿ”„ changed signature of GQLType.typeOptions from f a -> GQLTypeOptions to f a -> GQLTypeOptions -> GQLTypeOptions.

    now you can write:

        typeOptions _ options = options { fieldLabelModifier = <my function> }
    

    0๏ธโƒฃ whre argument options is default gql options.

    • deexposed constructor of GQLTypeOptions.
    • Type name for parametrized types like One (Two Three) will be generated directly, concatenating them OneTwoThree instead of One_Two_Three.
    • Haskell Float was renamed to custom scalar type Float32.
    • Haskell Double now represents GraphQL Float.

    Minor Changes

    • ๐Ÿ—„ deprecated kinds INPUT, ENUM and OUTPUT in favor of more generalized kind TYPE. now you can derive INPUT, ENUM and OUTPUT automatically with deriving (Generic, GQLType).
    • more likely to rebuild when a file loaded by importGQLDocument or importGQLDocumentWithNamespace is changed