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

Generate 'Schema.hs' Haskell GraphQL Type Definitions and Resolvers from 'Schema.gql' #184

Closed
nalchevanidze opened this issue Jul 7, 2019 · 6 comments
Labels
feature Proposal question Further information is requested

Comments

@nalchevanidze
Copy link
Member

nalchevanidze commented Jul 7, 2019

Morpheus CLI that converts

schema.gql

type Query {
  deity(name: String!, mythology: String): Deity
} 

type Deity {
  fullName: String!
  power : String
} 

to haskell API with default Values:

Api.hs

data Query = Query
{ deity :: DeityArgs -> ResM Deity
} deriving (Generic)

rootResolver :: GQLRootResolver IO Query () ()
rootResolver =
  GQLRootResolver
    { queryResolver = return Query {deity = resolveDeity}
    , mutationResolver = return ()
    , subscriptionResolver = return ()
    }

api :: ByteString -> IO ByteString
api = interpreter rootResolver

Deity.hs

data Deity = Deity
{ fullName :: Text
, power :: Maybe Text
} deriving (Generic)

instance GQLType Deity where
    type KIND Deity = OBJECT

data DeityArgs = DeityArgs
{ name :: Text
, mythology :: Maybe Text
} deriving (Generic)


resolveDeity :: DeityArgs -> ResM Deity
resolveDeity _ = return Deity {
    fullName = "",
    power = Nothing
}

so can be easily Migrated GraphQL api from node.js or any other Language

@nalchevanidze nalchevanidze changed the title Generate 'Schema.hs' Haskell GraphQL Type Definition (only types without resolvers) from 'Schema.gql' Generate 'Schema.hs' Haskell GraphQL Type Definitions (only types without resolvers) from 'Schema.gql' Jul 7, 2019
@nalchevanidze nalchevanidze added feature Proposal question Further information is requested labels Jul 7, 2019
@nalchevanidze nalchevanidze moved this from To do to In progress in Release 0.2.0 Beta Jul 25, 2019
@sordina
Copy link
Contributor

sordina commented Aug 1, 2019

It would be excellent to be able to do this with template-haskell in order to effectively create Haskell clients for 3rd party graphql sites.

@nalchevanidze
Copy link
Member Author

hi, @sordina i did not understand what do you mean, could you explain it with an example?

@nalchevanidze nalchevanidze changed the title Generate 'Schema.hs' Haskell GraphQL Type Definitions (only types without resolvers) from 'Schema.gql' Generate 'Schema.hs' Haskell GraphQL Type Definitions and Resolvers from 'Schema.gql' Aug 1, 2019
@sordina
Copy link
Contributor

sordina commented Aug 5, 2019

Hi @nalchevanidze apologies for the rambling comment. I think I hadn't had much sleep when I wrote that! I'll explain my use-case:

  • 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
  • I would love it if there was a template-haskell implementation of the codegen
    • So that I could point a module directly at the schema query, or saved file
  • Even better, there would be a way to perfrom a 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
    1. Run the query by calling the function, validating and marshalling the results.

Does that make sense? After working with some other GraphQL libraries from Haskell and other languages I've found that they are all a little frustrating to use, either too unsafe, or too underpowered, and it would be wonderful to see Haskell's strengths leveraged to give the best possible experience when working with GraphQL!

@nalchevanidze
Copy link
Member Author

nalchevanidze commented Aug 6, 2019

as i see, you need Haskell Client with compile time query validation?

like this.

Screenshot 2019-08-06 at 20 53 54

sounds good, i started working on it. #199

label of this issue was to generate GraphQL Api with schema.gql and is done with last pull request.

morpheus CLI

morpheus build  schema.gql  Api.hs

generates whole api with dummy resolvers. so i am going to close it.

your request is related to GraphQL Haskell Client.
so i would propose that you open new issue for it :)

@sordina
Copy link
Contributor

sordina commented Aug 7, 2019

Hi @nalchevanidze awesome! Thanks!

@sordina
Copy link
Contributor

sordina commented Aug 7, 2019

Actually, now that I reflect on this, the QQ example isn't quite what I'd envisioned, in that there isn't a datatype specialised to the fields requested, there doesn't seem to be a way to reference parameters, and the query isn't defined that returns that datatype. That said you're right this is a separate issue than the current one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposal question Further information is requested
Projects
No open projects
Development

No branches or pull requests

2 participants