Skip to content

morpheus-graphql-0.10.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@nalchevanidze nalchevanidze released this 07 Jan 16:40
7c4bc7c

Breaking Changes

  • all constructors of Resolver: QueryResolver,MutResolver,SubResolver are unexposed. use lift , publish or subscribe instead.
    e.g

    -- Query Resolver
    resolveUser :: ResolveQ EVENT IO User
    resolveUser = lift getDBUser
    
    -- Mutation Resolver
    resolveCreateUser :: ResolveM EVENT IO User
    resolveCreateUser = do
      publish [userUpdate] -- publishes event inside mutation
      lift setDBUser
    
    -- Subscription Resolver
    resolveNewUser :: ResolveS EVENT IO User
    resolveNewUser = subscribe [USER] $ do
      pure $ \(Event _ content) -> lift (getDBUserByContent content)

New features

  • exposed publish for mutation resolvers, now you can write

    resolveCreateUser :: ResolveM EVENT IO User
    resolveCreateUser = do
        requireAuthorized
        publish [userUpdate]
        liftEither setDBUser
  • exposed subscribe for subscription resolvers, now you can write

    resolveNewUser :: ResolveS EVENT IO User
    resolveNewUser = subscribe [USER] $ do
        requireAuthorized
        pure userByEvent
      where userByEvent (Event _ content) = liftEither (getDBUser content)
  • type SubField will convert your subscription monad to query monad.
    SubField (Resolver Subscription Event IO) User will generate same as
    Resolver Subscription Event IO (User ((Resolver QUERY Event IO)))

    now if you can define subscription as follows

    data Subscription m = Subscription {
      newUser :: SubField m User
    }
  • unsafeInternalContext to get resolver context, use only if it really necessary.
    the code depending on it may break even on minor version changes.

    resolveUser :: ResolveQ EVENT IO User
    resolveUser = do
      Context { currentSelection, schema, operation } <- unsafeInternalContext
      lift (getDBUser currentSelection)

Minor

  • MonadIO instance for resolvers. Thanks @dandoh
  • Example using STM, authentication, monad transformers. Thanks @dandoh
  • added dependency mtl