-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove crud in favor of gql controller
- Loading branch information
1 parent
87af4af
commit f7233c7
Showing
66 changed files
with
8,170 additions
and
4,072 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"makefile.configureOnOpen": false, | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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 |
---|---|---|
|
@@ -74,4 +74,5 @@ gem "httparty", "~> 0.22.0" | |
gem "jwt" | ||
gem "memery" | ||
gem "oj" | ||
gem "blueprinter" | ||
|
||
gem "graphql", "~> 2.3" |
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
7 changes: 0 additions & 7 deletions
7
apps/govquests-api/rails_app/app/blueprints/action_blueprint.rb
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
apps/govquests-api/rails_app/app/blueprints/action_execution_blueprint.rb
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
apps/govquests-api/rails_app/app/blueprints/quest_blueprint.rb
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
apps/govquests-api/rails_app/app/controllers/action_executions_controller.rb
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
apps/govquests-api/rails_app/app/controllers/graphql_controller.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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
class GraphqlController < ApplicationController | ||
# If accessing from outside this domain, nullify the session | ||
# This allows for outside API access while preventing CSRF attacks, | ||
# but you'll have to authenticate your user separately | ||
# protect_from_forgery with: :null_session | ||
|
||
def execute | ||
variables = prepare_variables(params[:variables]) | ||
query = params[:query] | ||
operation_name = params[:operationName] | ||
context = { | ||
current_user: current_user | ||
} | ||
result = GovquestsApiSchema.execute(query, variables: variables, context: context, operation_name: operation_name) | ||
render json: result | ||
rescue => e | ||
raise e unless Rails.env.development? | ||
handle_error_in_development(e) | ||
end | ||
|
||
private | ||
|
||
# Handle variables in form data, JSON body, or a blank value | ||
def prepare_variables(variables_param) | ||
case variables_param | ||
when String | ||
if variables_param.present? | ||
JSON.parse(variables_param) || {} | ||
else | ||
{} | ||
end | ||
when Hash | ||
variables_param | ||
when ActionController::Parameters | ||
variables_param.to_unsafe_hash # GraphQL-Ruby will validate name and type of incoming variables. | ||
when nil | ||
{} | ||
else | ||
raise ArgumentError, "Unexpected parameter: #{variables_param}" | ||
end | ||
end | ||
|
||
def handle_error_in_development(e) | ||
logger.error e.message | ||
logger.error e.backtrace.join("\n") | ||
|
||
render json: {errors: [{message: e.message, backtrace: e.backtrace}], data: {}}, status: 500 | ||
end | ||
end |
37 changes: 0 additions & 37 deletions
37
...ovquests-api/rails_app/app/controllers/integrations/gitcoin_passport_scores_controller.rb
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
apps/govquests-api/rails_app/app/controllers/quests_controller.rb
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
apps/govquests-api/rails_app/app/graphql/govquests_api_schema.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,45 @@ | ||
# frozen_string_literal: true | ||
|
||
class GovquestsApiSchema < GraphQL::Schema | ||
mutation(Types::MutationType) | ||
query(Types::QueryType) | ||
|
||
# For batch-loading (see https://graphql-ruby.org/dataloader/overview.html) | ||
use GraphQL::Dataloader | ||
|
||
# GraphQL-Ruby calls this when something goes wrong while running a query: | ||
def self.type_error(err, context) | ||
# if err.is_a?(GraphQL::InvalidNullError) | ||
# # report to your bug tracker here | ||
# return nil | ||
# end | ||
super | ||
end | ||
|
||
# Union and Interface Resolution | ||
def self.resolve_type(abstract_type, obj, ctx) | ||
# TODO: Implement this method | ||
# to return the correct GraphQL object type for `obj` | ||
raise(GraphQL::RequiredImplementationMissingError) | ||
end | ||
|
||
# Limit the size of incoming queries: | ||
max_query_string_tokens(5000) | ||
|
||
# Stop validating when it encounters this many errors: | ||
validate_max_errors(100) | ||
|
||
# Relay-style Object Identification: | ||
|
||
# Return a string UUID for `object` | ||
def self.id_from_object(object, type_definition, query_ctx) | ||
# For example, use Rails' GlobalID library (https://github.com/rails/globalid): | ||
object.to_gid_param | ||
end | ||
|
||
# Given a string UUID, find the object | ||
def self.object_from_id(global_id, query_ctx) | ||
# For example, use Rails' GlobalID library (https://github.com/rails/globalid): | ||
GlobalID.find(global_id) | ||
end | ||
end |
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
apps/govquests-api/rails_app/app/graphql/mutations/base_mutation.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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutations | ||
class BaseMutation < GraphQL::Schema::RelayClassicMutation | ||
argument_class Types::BaseArgument | ||
field_class Types::BaseField | ||
input_object_class Types::BaseInputObject | ||
object_class Types::BaseObject | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
apps/govquests-api/rails_app/app/graphql/mutations/complete_action_execution.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,31 @@ | ||
module Mutations | ||
class CompleteActionExecution < BaseMutation | ||
argument :execution_id, ID, required: true | ||
argument :nonce, String, required: true | ||
argument :completion_data, GraphQL::Types::JSON, required: false | ||
|
||
field :action_execution, Types::ActionExecutionType, null: true | ||
field :errors, [String], null: false | ||
|
||
def resolve(execution_id:, nonce:, completion_data: {}) | ||
result = ActionTracking::ActionExecutionService.complete( | ||
execution_id: execution_id, | ||
nonce: nonce, | ||
user_id: context[:current_user]&.user_id, | ||
completion_data: completion_data | ||
) | ||
|
||
if result.is_a?(ActionTracking::ActionExecutionReadModel) | ||
{ | ||
action_execution: result, | ||
errors: [] | ||
} | ||
else | ||
{ | ||
action_execution: nil, | ||
errors: [result[:error]] | ||
} | ||
end | ||
end | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
apps/govquests-api/rails_app/app/graphql/mutations/start_action_execution.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,30 @@ | ||
# app/graphql/mutations/start_action_execution.rb | ||
module Mutations | ||
class StartActionExecution < BaseMutation | ||
argument :action_id, ID, required: true | ||
argument :start_data, GraphQL::Types::JSON, required: false | ||
|
||
field :action_execution, Types::ActionExecutionType, null: true | ||
field :errors, [String], null: false | ||
|
||
def resolve(action_id:, start_data: {}) | ||
result = ActionTracking::ActionExecutionService.start( | ||
action_id: action_id, | ||
user_id: context[:current_user]&.user_id, | ||
start_data: start_data | ||
) | ||
|
||
if result.is_a?(ActionTracking::ActionExecutionReadModel) | ||
{ | ||
action_execution: result, | ||
errors: [] | ||
} | ||
else | ||
{ | ||
action_execution: nil, | ||
errors: [result[:error]] | ||
} | ||
end | ||
end | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
apps/govquests-api/rails_app/app/graphql/resolvers/base_resolver.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,6 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resolvers | ||
class BaseResolver < GraphQL::Schema::Resolver | ||
end | ||
end |
Oops, something went wrong.