-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
33 changed files
with
793 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Refinery | ||
module Api | ||
class GraphqlController < Refinery::AdminController | ||
|
||
def execute | ||
query = params[:query] | ||
variables = params[:variables] || {} | ||
|
||
begin | ||
result = Refinery::Api::GraphqlSchema.execute(query, variables: variables, context: context) | ||
rescue => error | ||
result = { errors: [{ message: error.message }] } | ||
end | ||
|
||
render json: result | ||
end | ||
|
||
private | ||
|
||
def context | ||
{ | ||
current_user: current_refinery_user | ||
} | ||
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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Fields | ||
module Pages | ||
class PageField < GraphQL::Schema::Field | ||
name 'Page' | ||
description 'Find a page by ID' | ||
|
||
type Types::Pages::PageType | ||
argument :id, !types.ID | ||
|
||
resolve -> (obj, args, ctx) { | ||
Refinery::Page.find_by_id(args[:id]) | ||
} | ||
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Fields | ||
module Pages | ||
class PagesField < GraphQL::Schema::Field | ||
name 'Pages' | ||
description 'Find all pages' | ||
|
||
type types[Types::Pages::PageType] | ||
|
||
resolve -> (obj, args, ctx) { | ||
Refinery::Page.all | ||
} | ||
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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
class GraphqlSchema < GraphQL::Schema | ||
query Types::QueryType | ||
mutation Types::MutationType | ||
|
||
resolve_type -> (obj, args, ctx) { | ||
type_name = obj.class.name | ||
Schema.types[type_name] | ||
} | ||
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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Inputs | ||
module Pages | ||
class PageInput < GraphQL::Schema::InputObject | ||
name 'PageInput' | ||
|
||
input_field :parent_id, types.Int | ||
input_field :path, types.String | ||
input_field :show_in_menu, types.Boolean | ||
input_field :link_url, types.String | ||
input_field :menu_match, types.String | ||
input_field :deletable, types.Boolean | ||
input_field :draft, types.Boolean | ||
input_field :skip_to_first_child, types.Boolean | ||
input_field :lft, types.Int | ||
input_field :rgt, types.Int | ||
input_field :depth, types.Int | ||
input_field :view_template, types.String | ||
input_field :layout_template, types.String | ||
input_field :locale, types.String | ||
input_field :title, types.String | ||
input_field :custom_slug, types.String | ||
input_field :menu_title, types.String | ||
input_field :slug, types.String | ||
input_field :meta_description, types.String | ||
input_field :browser_title, types.String | ||
|
||
input_field :parts, types[Inputs::Pages::PagePartInput] | ||
end | ||
end | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
api/app/graph/refinery/api/inputs/pages/page_part_input.rb
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Inputs | ||
module Pages | ||
class PagePartInput < GraphQL::Schema::InputObject | ||
name 'PagePartInput' | ||
|
||
input_field :slug, types.String | ||
input_field :position, types.Int | ||
input_field :title, types.String | ||
|
||
input_field :locale, types.String | ||
input_field :body, types.String | ||
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Mutations | ||
module Pages | ||
class Create < GraphQL::Schema::Mutation | ||
name 'CreatePage' | ||
description 'Create a page' | ||
|
||
input_field :page, !Inputs::Pages::PageInput | ||
|
||
return_field :page, Types::Pages::PageType | ||
|
||
resolve -> (obj, inputs, ctx) { | ||
inputs = inputs.to_h.deep_symbolize_keys | ||
|
||
page = Refinery::Page.create!(inputs[:page]) | ||
|
||
{ page: page } | ||
} | ||
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Mutations | ||
module Pages | ||
class Delete < GraphQL::Schema::Mutation | ||
name 'DeletePage' | ||
|
||
input_field :id, !types.ID | ||
|
||
return_field :page, Types::Pages::PageType | ||
|
||
resolve -> (obj, inputs, ctx) { | ||
page = Refinery::Page.destroy(inputs[:id]) | ||
|
||
{ page: page } | ||
} | ||
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Mutations | ||
module Pages | ||
class Update < GraphQL::Schema::Mutation | ||
name 'UpdatePage' | ||
description 'Create a page' | ||
|
||
input_field :id, !types.ID | ||
input_field :page, !Inputs::Pages::PageInput | ||
|
||
return_field :page, Types::Pages::PageType | ||
|
||
resolve -> (obj, inputs, ctx) { | ||
inputs = inputs.to_h.deep_symbolize_keys | ||
|
||
page = Refinery::Page.update(inputs[:id], inputs[:page]) | ||
|
||
{ page: page } | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
api/app/graph/refinery/api/types/active_record_interface.rb
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Types | ||
ActiveRecordInterface = GraphQL::InterfaceType.define do | ||
name "ActiveRecord" | ||
description "Active Record Interface" | ||
|
||
field :id, !types.ID | ||
field :updated_at do | ||
type Types::DateType | ||
resolve -> (obj, args, ctx) { | ||
obj.updated_at | ||
} | ||
end | ||
field :created_at do | ||
type Types::DateType | ||
resolve -> (obj, args, ctx) { | ||
obj.created_at | ||
} | ||
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,9 @@ | ||
module Refinery | ||
module Api | ||
module Types | ||
class BaseInterface | ||
include GraphQL::Schema::Interface | ||
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,8 @@ | ||
module Refinery | ||
module Api | ||
module Types | ||
class BaseObject < GraphQL::Schema::Object | ||
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Types | ||
DateType = GraphQL::ScalarType.define do | ||
name "Date" | ||
description "Valid date format (parsable by Ruby's Date.parse)" | ||
|
||
coerce_input -> (value, context) do | ||
begin Date.parse(value) | ||
value.to_datetime | ||
rescue ArgumentError => error | ||
context.errors << error.message | ||
end | ||
end | ||
|
||
coerce_result -> (value, context) do | ||
value.to_datetime | ||
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Types | ||
class MutationType < Types::BaseObject | ||
name 'Mutation' | ||
description 'The mutation root for this schema' | ||
|
||
field :createPage, mutation: Mutations::Pages::Create | ||
field :updatePage, mutation: Mutations::Pages::Update | ||
field :deletePage, mutation: Mutations::Pages::Delete | ||
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Refinery | ||
module Api | ||
module Types | ||
module Pages | ||
class PagePartType < GraphQL::Schema::Object | ||
name "PagePart" | ||
description "A PagePart" | ||
|
||
interfaces [Types::ActiveRecordInterface] | ||
|
||
field :slug, types.String | ||
field :position, types.Int | ||
field :title, types.String | ||
|
||
field :locale, types.String | ||
field :body, types.String | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.