DEV Community

Building blog CMS in ReasonML with GraphQL and Serverless using Hasura

Vladimir Novick on June 21, 2019

This is the first part of blog post series where we will create blog cms using Hasura for GraphQL API, and serverless functions for logic and on th...
Collapse
 
idkjs profile image
Alain

Looks like you don't have the user field set up on posts type. You have user_id so how would you return the name and avatar from the users table?

this query doesnt work if i have the same set up as you:

query getPosts {
  posts {
    title
    cover_img
    content
    created_at
    user {
      name
      avatar_url
    }
  }
}

Collapse
 
idkjs profile image
Alain

Solution is tracking the foreign keys on your tables. See:docs.hasura.io/1.0/graphql/manual/...

Collapse
 
vladimirnovick profile image
Vladimir Novick

Not exactly. an easier solution is what I wrote. You need to add relationships in relationships tab. I added a screenshot to clarify

Collapse
 
fakenickels profile image
Gabriel Rubens Abreu

Nice article!

One small thing though about this part

But before that, I want to receive my GraphQL API result typed, so I want to convert it to Records.

The result already comes typed but as a bound object ({ . "etc": int}) so saying "to receive the result typed" can be a bit confusing for beginners IMO

Collapse
 
vladimirnovick profile image
Vladimir Novick

I would always prefer Reason over typescript because you actually don’t need to type lots of things because compiler will infer types, but you have to be aware of the fact that Reason only looks like JavaScript. It’s way more powerful but you need to understand functional programming constructs such as pattern matching, variants and more. I suggest checking my YouTube channel for 10h ReasonML bootcamp that will cover the basics and even some advanced parts of ReasonML. And soon there will be more content on ReasonReact so stay tuned.

Collapse
 
syntakker profile image
syntakker

It's "Hindley Milner", not "Hindler Miller" type system.

 
vladimirnovick profile image
Vladimir Novick

It was 4 days online bootcamp 3+ h every day.