-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
91 changed files
with
372 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
module Graph | ||
Schema = GraphQL::Schema.define do | ||
query Graph::Types::RootQuery | ||
max_depth 5 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
module Graph | ||
module Types | ||
Article = GraphQL::ObjectType.define do | ||
name 'Article' | ||
description 'A blog entry' | ||
|
||
field :id, types.String | ||
field :title, types.String | ||
field :body, types.String do | ||
resolve -> (obj, _args, _context) do | ||
obj.newest_revision.body | ||
end | ||
end | ||
field :html, types.String do | ||
resolve -> (obj, _args, _context) do | ||
obj.newest_revision.markdown_html | ||
end | ||
end | ||
field :tags, types[Types::Tag] do | ||
resolve -> (obj, _args, _context) do | ||
obj.tags | ||
end | ||
end | ||
field :user, -> { Types::User } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
module Graph | ||
module Types | ||
RootQuery = GraphQL::ObjectType.define do | ||
name 'RootQuery' | ||
description 'The query root' | ||
|
||
field :article do | ||
type -> { Types::Article } | ||
description 'Get an article' | ||
|
||
argument :id, types.String | ||
|
||
resolve -> (_object, args, context) do | ||
::Article.find(args[:id]).tap do |article| | ||
context[:pundit].authorize(article, :show?) | ||
end.decorate | ||
end | ||
end | ||
|
||
field :articles do | ||
type -> { types[Types::Article] } | ||
description 'Get articles' | ||
|
||
argument :size, types.Int, 'get size', default_value: 10 | ||
argument :page, types.Int, 'page', default_value: 1 | ||
|
||
resolve -> (_object, args, _context) do | ||
size = [[args[:size], 25].min, 1].max | ||
page = [[args[:page], 100].min, 1].max | ||
::Article.public_items.page(page).per(size).decorate | ||
end | ||
end | ||
|
||
field :user do | ||
type -> { Types::User } | ||
description 'Get a user' | ||
|
||
argument :id, types.Int | ||
|
||
resolve -> (_object, args, context) do | ||
::User.find(args[:id]).tap do |user| | ||
context[:pundit].authorize(user, :show?) | ||
end.decorate | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
module Graph | ||
module Types | ||
Tag = GraphQL::ObjectType.define do | ||
name 'Tag' | ||
description 'A tag' | ||
|
||
field :name, types.String | ||
field :code, types.String, property: :content | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
module Graph | ||
module Types | ||
User = GraphQL::ObjectType.define do | ||
name 'User' | ||
description 'A user' | ||
|
||
field :id, types.Int | ||
field :name, types.String | ||
field :url, types.String | ||
field :avatarURL, types.String, property: :avatar_url | ||
field :stockCount, types.Int, property: :stock_count | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
class ArticleBuilder | ||
def initialize(article) | ||
@article = article | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
class CommentBuilder | ||
def initialize(article) | ||
@article = article | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
class LobbiesController < ApplicationController | ||
before_action :set_page | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
class QueriesController < ApplicationController | ||
skip_before_action :verify_authenticity_token | ||
before_action :check_csrf | ||
|
||
# POST /graphql.json | ||
def create | ||
query = params[:query].to_s | ||
render json: Graph::Schema.execute( | ||
query, | ||
context: { | ||
variables: param_variables, | ||
access_token: current_access_token, | ||
pundit: self | ||
} | ||
) | ||
end | ||
|
||
private | ||
|
||
def current_access_token | ||
if params[:token].present? | ||
AccessToken.find_by(token: params[:token]) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def private_mode! | ||
raise Errors::Unauthorized unless current_access_token.try(:user) | ||
end | ||
|
||
def check_csrf | ||
raise Errors::UnprocessableEntity unless request.headers['Host'] == safe_host | ||
x_from = request.headers['X-From'] | ||
raise Errors::UnprocessableEntity if x_from.blank? | ||
origin = request.headers['Origin'] | ||
raise Errors::UnprocessableEntity if origin && origin != 'null' && !x_from.start_with?("#{origin}/") | ||
end | ||
|
||
def safe_host | ||
GlobalSetting.root_url.match(/\/(?<host>[^\/]+)(?:\/|\z)/).try(:[], :host) | ||
end | ||
|
||
def param_variables | ||
variables = params[:variables] | ||
if variables.blank? | ||
{} | ||
elsif variables.is_a?(String) | ||
JSON.parse(variables, quirks_mode: true) | ||
else | ||
variables | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'digest/md5' | ||
|
||
class UserDecorator < Draper::Decorator | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
module ApplicationHelper | ||
def current_user | ||
@current_user | ||
|
Oops, something went wrong.