Skip to content

Wolfpack-Digital/blogposts_graphql_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

 rails new blogposts_graphql_api --skip-test --api
> rails g model User email:string name:string
> rails g model Blogpost user:belongs_to title:string body:text
  • add dependencies

  • install them

  rails generate graphql:install
  bundle
  rails generate graphql:object user
  rails generate graphql:object blogpost
  • add faker gem
  • bundle
  • add seeds
  • rails db:seed

Query

  query {
    users {
      name
      id
      blogpostsCount
      blogposts {
        id
        title
        bodyShort
        body
      }
    }
  }
  mutation {
    createUser(input: {
      name: "Florin Ionce",
      email: "[email protected]"
    }) {
      user {
        id
        name
        email
      }
      errors
    }
  }
  • add unique validation on user email
  rails g migration add_unique_index_to_user_email

About

Ruby on Rails Graphql Example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published