Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Morpheus GraphQL Client with Safe Queries/Mutations #200

Closed
sordina opened this issue Aug 8, 2019 · 2 comments
Closed

Morpheus GraphQL Client with Safe Queries/Mutations #200

sordina opened this issue Aug 8, 2019 · 2 comments

Comments

@sordina
Copy link
Contributor

sordina commented Aug 8, 2019

Spinning off from #184

  • Currently we develop some Rails applications that expose a GraphQL API
  • I would like to consume that API with Haskell Applications
  • It would be good to have a code-gen tool that takes these schemas and generates Haskell
  • There should be a way to perfrom a parameterized query/mutation in 3-phases:
    1. Codegen from the Schema (Haskell implementation of the queries/mutations/types)
    2. Codegen from the query
    • Check that the query matches the schema
    • Generate a Haskell function to perform the query with just the required params/fields
    • Generate a datatype representing the response from that query (possibly with lenses for fields) so that there are no Maybe fields for requested non-null fields.
    1. Run the query by calling the function, validating and marshaling the results.

Let me know if this is a duplicate issue!

@nalchevanidze
Copy link
Member

nalchevanidze commented Aug 8, 2019

Vision:

schema :: IO GQLSchema
schema = <get schema from GQL Api or doc file> 

query schema [gql|
   query GetHero ($id: Int ) {
       name
       hobby (id:)
       age
   }
]

should:

  1. validate Query/Mutation
  2. generate Data type Declaration GetHero:
  data GetHero = GetHero {
     _name :: Text,
     _hobby ::  Maybe Text
     _age :: Int
  }

 data GetHeroArgs = {
    _id :: Int
 }
  1. generate lens instance for GetHero

  2. generate Fetch instance for GetHero where

     class Fetch var a where 
       fetch :: Monad m =>  (Request -> m Value) -> var  -> m (Either Error a)

so that :

  fetchFromServer :: Request -> IO Value
  fetchFromServer req = <fetch value from server>

  fetchHero :: IO (Either Error GetHero)
  fetchHero = fetch  fetchFromServer  (GetHeroArgs { id = 2 })

@sordina , if there is something to add please let me know.

@nalchevanidze nalchevanidze changed the title Safe Queries/Mutationss Morpheus GraphQL Client with Safe Queries/Mutationss Aug 14, 2019
@nalchevanidze nalchevanidze changed the title Morpheus GraphQL Client with Safe Queries/Mutationss Morpheus GraphQL Client with Safe Queries/Mutations Aug 14, 2019
@nalchevanidze
Copy link
Member

nalchevanidze commented Aug 24, 2019

in release v0.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants