morpheus-graphql icon indicating copy to clipboard operation
morpheus-graphql copied to clipboard

Concurrent Execution for Query and Subscription, but Serial for Mutation

Open nalchevanidze opened this issue 5 years ago • 7 comments

nalchevanidze avatar Jan 07 '20 15:01 nalchevanidze

Can you elaborate? Under the hood what are shared between executions (query/mutation/subscription)? Why can't we do mutations concurrently?

dandoh avatar Jan 07 '20 15:01 dandoh

Why can't we do mutations concurrently?

it is GraphQL specification:

Serial execution of the provided mutations ensures against race conditions during these side‐effects.

https://graphql.github.io/graphql-spec/June2018/#sec-Mutation

how we can implement it, is another question.

nalchevanidze avatar Jan 07 '20 16:01 nalchevanidze

Ahh, it says that in each request, top-level selection set of mutation should be executed in sequence. This makes senses.

At first I thought all the mutation requests send to server should be processed serially (which is hindsight, morpheus has no control over that).

dandoh avatar Jan 07 '20 16:01 dandoh

but i think we have control over Execution. ResultT m transformer can decide how to execute monad m for lists and object fields.

nalchevanidze avatar Jan 07 '20 18:01 nalchevanidze

but i think we have control over Execution. ResultT m transformer can decide how to execute monad m for lists and object fields.

Yeah. But not over a scotty webserver where requests are processed concurrently, right?

dandoh avatar Jan 08 '20 01:01 dandoh

@dandoh could you evaluate. how we could implement it?

i don't deep knowledge of it but may they do what we want.

  • https://hackage.haskell.org/package/base-4.11.1.0/docs/Control-Concurrent.html
  • https://hackage.haskell.org/package/parallel-3.2.2.0/docs/Control-Parallel-Strategies.html#history

the idea is that according to typeVariable (concurency :: Bool) Result and ResultT

https://github.com/morpheusgraphql/morpheus-graphql/blob/7c4bc7c968353f6bb1378350f6b2adf0fc145474/src/Data/Morpheus/Types/Internal/Resolving/Core.hs#L108-L110

and

https://github.com/morpheusgraphql/morpheus-graphql/blob/7c4bc7c968353f6bb1378350f6b2adf0fc145474/src/Data/Morpheus/Types/Internal/Resolving/Core.hs#L138-L140

change execution strategy (serial vs parallel).

or

https://github.com/morpheusgraphql/morpheus-graphql/blob/7c4bc7c968353f6bb1378350f6b2adf0fc145474/src/Data/Morpheus/Types/Internal/Resolving/Resolver.hs#L374-L379

just concentrate to serially execute fields on mutations

nalchevanidze avatar Jan 08 '20 20:01 nalchevanidze

I might have some ideas, but let me do experiments first.

dandoh avatar Jan 09 '20 10:01 dandoh

i think it works perfectly without. if someone will require this feature we can reopen it

nalchevanidze avatar Aug 31 '22 20:08 nalchevanidze