项目作者: Aristat

项目描述 :
Rails Graphql API example
高级语言: Ruby
项目地址: git://github.com/Aristat/rails-graphql-example-app.git
创建时间: 2019-06-21T19:06:37Z
项目社区:https://github.com/Aristat/rails-graphql-example-app

开源协议:

下载


Rails Graphql API

Getting started

Install rvm/rbenv, ruby, rails

Clone repository

  1. git clone git@github.com:Aristat/rails-graphql-example-app.git

Start

  1. bin/rails db:create
  2. bin/rails db:migrate
  3. bin/rails db:seed
  4. bundle exec rails s -p 3000
  5. localhost:3000/graphql

Code structure

  1. .
  2. ├── fixtures // fixtures for specs
  3. ├── db // migrations and seeds for DB
  4. └── app
  5. ├── graphql // graphql logic
  6. └── controllers/graphql_controller // graphql action with jwt auth

Generate token for auth

  1. bin/rails c
  2. JWTWrapper.generate_user_token(User.last)

this token set in headers -

  1. {
  2. "Authorization": "bearer example_token_from_console"
  3. }

Queries/Mutations

  1. query userProfile {
  2. userProfile {
  3. id
  4. name
  5. }
  6. }
  1. mutation updateUser($userInput: UserInput) {
  2. updateUser(userInput: $userInput) {
  3. ok
  4. errors {
  5. message
  6. type
  7. }
  8. }
  9. }
  1. query productBlock($productId: ID!) {
  2. product(id: $productId) {
  3. name
  4. typeObject
  5. itemsCount
  6. productItems {
  7. nodes {
  8. color
  9. price
  10. }
  11. }
  12. }
  13. }

Testing

  1. RAILS_ENV=test rspec spec/

Programs for testing

https://github.com/prisma/graphql-playground - for easy query writing