Skip to content

How to setup graphql queries, mutation and authentication with ruby on rails

Notifications You must be signed in to change notification settings

strativd/howtographql-rails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Each tutorial step is broken down in this repo's commit history
  1. Getting Started
  2. Queries
  3. Mutations
  4. Authentication
  5. Connecting Nodes
  6. Error Handling
  7. Filtering
  8. Pagination
  9. Summary

Installation

Install dependencies:

bundle install

rails db:setup

Starting the server:

rails server

Opening the application:

open http://localhost:3000/

Interesting Files:

Sample GraphQL Queries

List first 5 links containing "watch":

{
  searchLinks(
    first: 5,
    skip: 0,
    filter:{
      descriptionContains: "watch"
    }
  ) {
    url
    description
    postedBy {
      name
    }
  }
}

Creates new user:

mutation {
  createUser(
      name: "Testy McTester",
      authProvider: {
        credentials: {
          email: "[email protected]",
          password: "password"
        }
      }
  ) {
    email
    id
    name
  }
}

Creates new user token:

mutation {
  loginUser(
    credentials: {
    		email: "[email protected]",
      	password: "password"
  		}
  	) {
    token
    user {
      name
    }
  }
}

Creates new link:

mutation {
  createLink(
    description: "Watch NHL 🏒",
    url: "http://nhl.com"
  ) {
    description
    url
    id
    postedBy {
      id
    }
  }
}

Creates new vote:

mutation {
  createVote(
    linkId: "4"
  ) {
    link {
      description
      url
    }
  }
}

Get all links and votes, with the voter and their vote history:

{
  allLinks {
    url
    description
    id
    votes {
      user {
        name
        votes {
          link {
            url
            description
            id
          }
        }
      }
    }
  }
}

About

How to setup graphql queries, mutation and authentication with ruby on rails

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published