Testing GraphQL 1.3.0 in Travis
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -65,7 +65,7 @@ gem 'browser'
|
|||||||
gem 'turnout', '~> 2.4.0'
|
gem 'turnout', '~> 2.4.0'
|
||||||
gem 'redcarpet'
|
gem 'redcarpet'
|
||||||
|
|
||||||
gem 'graphql'
|
gem 'graphql', '~> 1.3.0'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ GEM
|
|||||||
activesupport (>= 4.1.0)
|
activesupport (>= 4.1.0)
|
||||||
graphiql-rails (1.3.0)
|
graphiql-rails (1.3.0)
|
||||||
rails
|
rails
|
||||||
graphql (0.18.11)
|
graphql (1.3.0)
|
||||||
groupdate (3.1.1)
|
groupdate (3.1.1)
|
||||||
activesupport (>= 3)
|
activesupport (>= 3)
|
||||||
gyoku (1.3.1)
|
gyoku (1.3.1)
|
||||||
@@ -484,7 +484,7 @@ DEPENDENCIES
|
|||||||
foundation_rails_helper (~> 2.0.0)
|
foundation_rails_helper (~> 2.0.0)
|
||||||
fuubar
|
fuubar
|
||||||
graphiql-rails
|
graphiql-rails
|
||||||
graphql
|
graphql (~> 1.3.0)
|
||||||
groupdate (~> 3.1.0)
|
groupdate (~> 3.1.0)
|
||||||
i18n-tasks
|
i18n-tasks
|
||||||
initialjs-rails (= 0.2.0.4)
|
initialjs-rails (= 0.2.0.4)
|
||||||
|
|||||||
@@ -8,8 +8,25 @@ class GraphqlController < ApplicationController
|
|||||||
|
|
||||||
def query
|
def query
|
||||||
begin
|
begin
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
|
api_types_creator = GraphQL::ApiTypesCreator.new(API_TYPE_DEFINITIONS)
|
||||||
|
created_api_types = api_types_creator.create
|
||||||
|
|
||||||
|
query_type_creator = GraphQL::QueryTypeCreator.new(created_api_types)
|
||||||
|
query_type = query_type_creator.create
|
||||||
|
|
||||||
|
consul_schema = GraphQL::Schema.define do
|
||||||
|
query query_type
|
||||||
|
max_depth 12
|
||||||
|
|
||||||
|
resolve_type -> (object, ctx) do
|
||||||
|
type_name = object.class.name # look up types by class name
|
||||||
|
ConsulSchema.types[type_name]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
set_query_environment
|
set_query_environment
|
||||||
response = ConsulSchema.execute query_string, variables: query_variables
|
response = consul_schema.execute query_string, variables: query_variables
|
||||||
render json: response, status: :ok
|
render json: response, status: :ok
|
||||||
rescue GraphqlController::QueryStringError
|
rescue GraphqlController::QueryStringError
|
||||||
render json: { message: 'Query string not present' }, status: :bad_request
|
render json: { message: 'Query string not present' }, status: :bad_request
|
||||||
|
|||||||
@@ -1,18 +1,2 @@
|
|||||||
api_config = YAML.load_file('./config/api.yml')
|
api_config = YAML.load_file('./config/api.yml')
|
||||||
api_type_definitions = GraphQL::ApiTypesCreator::parse_api_config_file(api_config)
|
API_TYPE_DEFINITIONS = GraphQL::ApiTypesCreator::parse_api_config_file(api_config)
|
||||||
|
|
||||||
api_types_creator = GraphQL::ApiTypesCreator.new(api_type_definitions)
|
|
||||||
created_api_types = api_types_creator.create
|
|
||||||
|
|
||||||
query_type_creator = GraphQL::QueryTypeCreator.new(created_api_types)
|
|
||||||
QueryType = query_type_creator.create
|
|
||||||
|
|
||||||
ConsulSchema = GraphQL::Schema.define do
|
|
||||||
query QueryType
|
|
||||||
max_depth 12
|
|
||||||
|
|
||||||
resolve_type -> (object, ctx) do
|
|
||||||
type_name = object.class.name # look up types by class name
|
|
||||||
ConsulSchema.types[type_name]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
@@ -1,5 +1,23 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
api_types_creator = GraphQL::ApiTypesCreator.new(API_TYPE_DEFINITIONS)
|
||||||
|
created_api_types = api_types_creator.create
|
||||||
|
|
||||||
|
query_type_creator = GraphQL::QueryTypeCreator.new(created_api_types)
|
||||||
|
QueryType = query_type_creator.create
|
||||||
|
|
||||||
|
ConsulSchema = GraphQL::Schema.define do
|
||||||
|
query QueryType
|
||||||
|
max_depth 12
|
||||||
|
|
||||||
|
resolve_type -> (object, ctx) do
|
||||||
|
type_name = object.class.name # look up types by class name
|
||||||
|
ConsulSchema.types[type_name]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
def execute(query_string, context = {}, variables = {})
|
def execute(query_string, context = {}, variables = {})
|
||||||
ConsulSchema.execute(query_string, context: context, variables: variables)
|
ConsulSchema.execute(query_string, context: context, variables: variables)
|
||||||
end
|
end
|
||||||
@@ -14,7 +32,7 @@ def hidden_field?(response, field_name)
|
|||||||
data_is_empty && error_is_present
|
data_is_empty && error_is_present
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ConsulSchema do
|
describe 'ConsulSchema' do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
let(:proposal) { create(:proposal, author: user) }
|
let(:proposal) { create(:proposal, author: user) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user