binda-api 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +84 -0
- data/Rakefile +26 -0
- data/app/controllers/binda/api/application_controller.rb +7 -0
- data/app/controllers/graphql_controller.rb +35 -0
- data/app/graphql/binda/api/fields/board_by_slug_field.rb +8 -0
- data/app/graphql/binda/api/fields/component_by_slug_field.rb +9 -0
- data/app/graphql/binda/api/fields/components_by_structure_field.rb +10 -0
- data/app/graphql/binda/api/fields/components_field.rb +11 -0
- data/app/graphql/binda/api/fields/repeaters_field.rb +10 -0
- data/app/graphql/binda/api/fields/structures_field.rb +6 -0
- data/app/graphql/binda/api/resolvers/board_by_slug_resolver.rb +5 -0
- data/app/graphql/binda/api/resolvers/component_by_slug_resolver.rb +5 -0
- data/app/graphql/binda/api/resolvers/components_by_structure_resolver.rb +5 -0
- data/app/graphql/binda/api/resolvers/components_resolver.rb +14 -0
- data/app/graphql/binda/api/resolvers/repeaters_resolver.rb +6 -0
- data/app/graphql/binda/api/resolvers/structures_resolver.rb +5 -0
- data/app/graphql/binda/api/schema.rb +8 -0
- data/app/graphql/binda/api/types/audio_type.rb +22 -0
- data/app/graphql/binda/api/types/board_type.rb +11 -0
- data/app/graphql/binda/api/types/checkbox_type.rb +18 -0
- data/app/graphql/binda/api/types/component_type.rb +13 -0
- data/app/graphql/binda/api/types/image_type.rb +28 -0
- data/app/graphql/binda/api/types/mutation_type.rb +11 -0
- data/app/graphql/binda/api/types/query_type.rb +11 -0
- data/app/graphql/binda/api/types/radio_type.rb +15 -0
- data/app/graphql/binda/api/types/repeater_type.rb +8 -0
- data/app/graphql/binda/api/types/selection_type.rb +16 -0
- data/app/graphql/binda/api/types/structure_type.rb +6 -0
- data/app/graphql/binda/api/types/svg_type.rb +10 -0
- data/app/graphql/binda/api/types/text_type.rb +10 -0
- data/app/graphql/binda/api/types/video_type.rb +22 -0
- data/app/helpers/binda/api/application_helper.rb +6 -0
- data/app/models/binda/api/application_record.rb +7 -0
- data/config/database.yml.travis +3 -0
- data/config/routes.rb +7 -0
- data/lib/binda/api.rb +8 -0
- data/lib/binda/api/engine.rb +21 -0
- data/lib/binda/api/fields.rb +111 -0
- data/lib/binda/api/version.rb +5 -0
- data/lib/tasks/binda/api_tasks.rake +4 -0
- metadata +243 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 314f92cda8132491aba8f9578ca7304a8c0ab84f
|
4
|
+
data.tar.gz: b61d424f831112ed415bdcca30ea693872ddeb21
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 20f2f402ae3cd2d88fb0fbb3fc77a7676386a29c6d41ac2e309288dc12f5c041047f2fb54b2b016289ae997a25dcca538a1ce9eed381261d9b5af36dd37a2e7e
|
7
|
+
data.tar.gz: edf1e7c0cd685f4496be108b24de281b7d28bb89a5b0cacbd6d241e3134b912943e8f428cbe3823c7ed5d82938c86b82427e4dce6a176b78663b15a45e1af0e9
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Marco Crepaldi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Binda API
|
2
|
+
A GraphQL API for [Binda CMS](http://github.com/lacolonia/binda).
|
3
|
+
|
4
|
+
**Binda** is a headless CMS with an intuitive out-of-the-box interface which makes very easy creating application infrastructures. For more info about Binda structure please visit the [official documentation](http://www.rubydoc.info/gems/binda)
|
5
|
+
|
6
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/d670f30b4635e5d7bb2a/maintainability)](https://codeclimate.com/github/lacolonia/binda-api/maintainability)
|
7
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/d670f30b4635e5d7bb2a/test_coverage)](https://codeclimate.com/github/lacolonia/binda-api/test_coverage)
|
8
|
+
|
9
|
+
# Quick start
|
10
|
+
Install Binda APi via terminal
|
11
|
+
|
12
|
+
```bash
|
13
|
+
gem install binda-api
|
14
|
+
```
|
15
|
+
|
16
|
+
alternatively add the gem to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'binda-api'
|
20
|
+
```
|
21
|
+
|
22
|
+
Then execute:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
(If you have installed Binda already you can skip next steps)
|
29
|
+
|
30
|
+
Setup the database. If you are going to use Postgres set it up now.
|
31
|
+
|
32
|
+
To complete binda installation run the installer from terminal. Binda will take you through a short configuration process where you will setup the first user and some basic details.
|
33
|
+
|
34
|
+
```bash
|
35
|
+
rails generate binda:install
|
36
|
+
```
|
37
|
+
|
38
|
+
Now you are good to go. Good job!
|
39
|
+
|
40
|
+
# Query
|
41
|
+
Binda API is based on [GraphQL](https://graphql.org).
|
42
|
+
|
43
|
+
Here below an example of a simple query that retrives the name of all `post` components using [Axios](https://github.com/axios/axios) library.
|
44
|
+
|
45
|
+
```javascript
|
46
|
+
axios
|
47
|
+
.post(
|
48
|
+
"http://my.domain.com/graphql",
|
49
|
+
{ query: "{ components(slug: \"post\"){ edges { node { name } } }}" },
|
50
|
+
{ headers: { "Content-Type": "application/json" } }
|
51
|
+
)
|
52
|
+
.then(response => response.data)
|
53
|
+
.catch(error => {
|
54
|
+
throw error;
|
55
|
+
})
|
56
|
+
```
|
57
|
+
|
58
|
+
This is one of the possible approaces to access Binda content with GraphQL. Feel free to make requests to GraphQL as you prefer.
|
59
|
+
|
60
|
+
## GraphiQL and Binda API documentation
|
61
|
+
Binda API documentation is integrated in the GraphiQL panel which is accessible from `/admin_panel/graphiql`. In your local environment this would be `http://localhost:3000/admin_panel/graphiql` (if you use port 3000).
|
62
|
+
|
63
|
+
## Absolute URL
|
64
|
+
If Binda is using a CDN to store all assets you should already receive a proper absolute URL. If insted you are storing assets inside public folder (see [Carrierwave documentation](https://github.com/carrierwaveuploader/carrierwave#configuring-carrierwave)) Binda API will give you a relative path.
|
65
|
+
|
66
|
+
You can fix this issue modify few lines of the CMS application on which Binda is installed.
|
67
|
+
|
68
|
+
Assuming that you set a environmental variable `BINDA_ASSET_HOST`
|
69
|
+
|
70
|
+
```yaml
|
71
|
+
BINDA_ASSET_HOST=http://your.domain.com
|
72
|
+
```
|
73
|
+
|
74
|
+
Add this line to `config/environments/production.rb`
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
config.action_controller.asset_host = ENV['BINDA_ASSET_HOST']
|
78
|
+
```
|
79
|
+
|
80
|
+
Add also this line to `config/initializers/carrierwave.rb`
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
config.asset_host = ActionController::Base.asset_host
|
84
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Binda::Api'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class GraphqlController < ApplicationController
|
2
|
+
protect_from_forgery with: :null_session
|
3
|
+
|
4
|
+
def execute
|
5
|
+
variables = ensure_hash(params[:variables])
|
6
|
+
query = params[:query]
|
7
|
+
operation_name = params[:operationName]
|
8
|
+
context = {
|
9
|
+
# Query context goes here, for example:
|
10
|
+
# current_user: current_user,
|
11
|
+
}
|
12
|
+
result = Binda::Api::Schema.execute(query, variables: variables, context: context, operation_name: operation_name)
|
13
|
+
render json: result
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# Handle form data, JSON body, or a blank value
|
19
|
+
def ensure_hash(ambiguous_param)
|
20
|
+
case ambiguous_param
|
21
|
+
when String
|
22
|
+
if ambiguous_param.present?
|
23
|
+
ensure_hash(JSON.parse(ambiguous_param))
|
24
|
+
else
|
25
|
+
{}
|
26
|
+
end
|
27
|
+
when Hash, ActionController::Parameters
|
28
|
+
ambiguous_param
|
29
|
+
when nil
|
30
|
+
{}
|
31
|
+
else
|
32
|
+
raise ArgumentError, "Unexpected parameter: #{ambiguous_param}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Binda::Api::Fields::ComponentsByStructureField = GraphQL::Field.define do
|
2
|
+
name 'componentsByStructure'
|
3
|
+
type Binda::Api::Types::ComponentType.connection_type
|
4
|
+
|
5
|
+
argument :slug, !types.String
|
6
|
+
argument :structure_slug, !types.String
|
7
|
+
argument :publish_state, !types.String
|
8
|
+
|
9
|
+
resolve(Binda::Api::Resolvers::ComponentsByStructureResolver.new)
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Binda::Api::Fields::ComponentsField = GraphQL::Field.define do
|
2
|
+
name 'components'
|
3
|
+
|
4
|
+
argument :slug, types.String.to_list_type
|
5
|
+
argument :structure_slug, types.String
|
6
|
+
argument :publish_state, types.String
|
7
|
+
|
8
|
+
type Binda::Api::Types::ComponentType.connection_type
|
9
|
+
|
10
|
+
resolve(Binda::Api::Resolvers::ComponentsResolver.new)
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Binda::Api::Fields::RepeatersField = GraphQL::Field.define do
|
2
|
+
name 'repeaters'
|
3
|
+
type Binda::Api::Types::RepeaterType.to_list_type
|
4
|
+
|
5
|
+
argument :slug, !types.String
|
6
|
+
argument :fieldable_slug, !types.String
|
7
|
+
|
8
|
+
resolve(Binda::Api::Resolvers::RepeatersResolver.new)
|
9
|
+
end
|
10
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Binda::Api::Resolvers::ComponentsResolver
|
2
|
+
def call(obj, args, ctx = {})
|
3
|
+
query_params = args.to_h.symbolize_keys
|
4
|
+
query_params.reject!{|k,v| [:first, :last, :after, :before].include? k }
|
5
|
+
structure_slug = query_params.delete(:structure_slug)
|
6
|
+
|
7
|
+
components = Binda::Component.where query_params
|
8
|
+
if structure_slug
|
9
|
+
components = components.includes(:structure).where(binda_structures: { slug: structure_slug })
|
10
|
+
end
|
11
|
+
|
12
|
+
components.order('binda_components.position ASC')
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
class Binda::Api::Resolvers::RepeatersResolver
|
2
|
+
def call(obj, args, ctx = {})
|
3
|
+
repeaters = Binda::Repeater.includes(:field_setting).where(binda_field_settings: { slug: args[:slug] }).order(:position)
|
4
|
+
repeaters.select{|r| r.fieldable.slug == args[:fieldable_slug] }
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Binda::Api::Types::AudioType = GraphQL::ObjectType.define do
|
2
|
+
name 'Binda_Audio'
|
3
|
+
|
4
|
+
field :audio, types.String do
|
5
|
+
resolve ->(obj, args, ctx) do
|
6
|
+
obj.audio.url
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
field :content_type, types.String do
|
11
|
+
resolve ->(obj, args, ctx) do
|
12
|
+
obj.content_type
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
field :file_size, types.String do
|
17
|
+
resolve ->(obj, args, ctx) do
|
18
|
+
obj.file_size
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'binda/api/fields'
|
2
|
+
|
3
|
+
Binda::Api::Types::BoardType = GraphQL::ObjectType.define do |context|
|
4
|
+
name "Binda_Board"
|
5
|
+
context.field :id, context.types.ID
|
6
|
+
context.field :name, context.types.String
|
7
|
+
context.field :slug, context.types.String
|
8
|
+
context.field :position, context.types.Int
|
9
|
+
|
10
|
+
::Binda::Api::Fields::SHARED_FIELDS.call(context)
|
11
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'binda/api/fields'
|
2
|
+
|
3
|
+
Binda::Api::Types::CheckboxType = GraphQL::ObjectType.define do
|
4
|
+
name 'Binda_Checkbox'
|
5
|
+
|
6
|
+
field :value, types.String do
|
7
|
+
resolve ->(obj, args, ctx) do
|
8
|
+
obj[:value]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
field :label, types.String do
|
13
|
+
resolve ->(obj, args, ctx) do
|
14
|
+
obj[:label]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'binda/api/fields'
|
2
|
+
|
3
|
+
Binda::Api::Types::ComponentType = GraphQL::ObjectType.define do |context|
|
4
|
+
name "Binda_Component"
|
5
|
+
context.field :id, context.types.ID
|
6
|
+
context.field :name, context.types.String
|
7
|
+
context.field :slug, context.types.String
|
8
|
+
context.field :publish_state, context.types.String
|
9
|
+
context.field :structure, ::Binda::Api::Types::StructureType
|
10
|
+
context.field :position, context.types.Int
|
11
|
+
|
12
|
+
::Binda::Api::Fields::SHARED_FIELDS.call(context)
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Binda::Api::Types::ImageType = GraphQL::ObjectType.define do
|
2
|
+
name 'Binda_Image'
|
3
|
+
|
4
|
+
field :image, types.String do
|
5
|
+
resolve ->(obj, args, ctx) do
|
6
|
+
obj.image.url
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
field :thumb, types.String do
|
11
|
+
resolve ->(obj, args, ctx) do
|
12
|
+
obj.image.thumb.url
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
field :width, types.String do
|
17
|
+
resolve ->(obj, args, ctx) do
|
18
|
+
obj.file_width.to_i
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
field :height, types.String do
|
23
|
+
resolve ->(obj, args, ctx) do
|
24
|
+
obj.file_height.to_i
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Binda::Api::Types::MutationType = GraphQL::ObjectType.define do
|
2
|
+
name "Mutation"
|
3
|
+
|
4
|
+
# TODO: Remove me
|
5
|
+
field :testField, types.String do
|
6
|
+
description "An example field added by the generator"
|
7
|
+
resolve ->(obj, args, ctx) {
|
8
|
+
"Hello World!"
|
9
|
+
}
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Binda::Api::Types::QueryType = GraphQL::ObjectType.define do
|
2
|
+
name "Query"
|
3
|
+
|
4
|
+
connection :structures, Binda::Api::Fields::StructuresField
|
5
|
+
connection :components, Binda::Api::Fields::ComponentsField
|
6
|
+
connection :components_by_structure, Binda::Api::Fields::ComponentsByStructureField
|
7
|
+
|
8
|
+
field :component_by_slug, Binda::Api::Fields::ComponentBySlugField
|
9
|
+
field :board_by_slug, Binda::Api::Fields::BoardBySlugField
|
10
|
+
field :repeaters, Binda::Api::Fields::RepeatersField
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Binda::Api::Types::RadioType = GraphQL::ObjectType.define do
|
2
|
+
name 'Binda_Radio'
|
3
|
+
|
4
|
+
field :value, types.String do
|
5
|
+
resolve ->(obj, args, ctx) do
|
6
|
+
obj[:value]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
field :label, types.String do
|
11
|
+
resolve ->(obj, args, ctx) do
|
12
|
+
obj[:label]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Binda::Api::Types::SelectionType = GraphQL::ObjectType.define do
|
2
|
+
name 'Binda_Selection'
|
3
|
+
|
4
|
+
field :value, types.String do
|
5
|
+
resolve ->(obj, args, ctx) do
|
6
|
+
obj[:value]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
field :label, types.String do
|
11
|
+
resolve ->(obj, args, ctx) do
|
12
|
+
obj[:label]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Binda::Api::Types::VideoType = GraphQL::ObjectType.define do
|
2
|
+
name 'Binda_Video'
|
3
|
+
|
4
|
+
field :video, types.String do
|
5
|
+
resolve ->(obj, args, ctx) do
|
6
|
+
obj.video.url
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
field :content_type, types.String do
|
11
|
+
resolve ->(obj, args, ctx) do
|
12
|
+
obj.content_type
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
field :file_size, types.String do
|
17
|
+
resolve ->(obj, args, ctx) do
|
18
|
+
obj.file_size
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/config/routes.rb
ADDED
data/lib/binda/api.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'binda'
|
2
|
+
require 'graphql'
|
3
|
+
require 'graphiql/rails'
|
4
|
+
require 'rack/cors'
|
5
|
+
|
6
|
+
module Binda
|
7
|
+
module Api
|
8
|
+
class Engine < ::Rails::Engine
|
9
|
+
isolate_namespace Binda::Api
|
10
|
+
|
11
|
+
initializer "add_rack_cors_middleware" do |app|
|
12
|
+
app.middleware.insert_before 0, Rack::Cors do
|
13
|
+
allow do
|
14
|
+
origins '*'
|
15
|
+
resource '*', :headers => :any, :methods => [:get, :post, :options]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module Binda
|
2
|
+
module Api
|
3
|
+
module Fields
|
4
|
+
SHARED_FIELDS = Proc.new do |context|
|
5
|
+
context.field :get_related_components, ::Binda::Api::Types::ComponentType.to_list_type do
|
6
|
+
argument :slug, !context.types.String
|
7
|
+
|
8
|
+
resolve ->(obj, args, ctx) {
|
9
|
+
obj.get_related_components(args[:slug])
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
context.field :get_related_boards, ::Binda::Api::Types::BoardType.to_list_type do
|
14
|
+
argument :slug, !context.types.String
|
15
|
+
|
16
|
+
resolve ->(obj, args, ctx) {
|
17
|
+
obj.get_related_boards(args[:slug])
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
context.field :get_string, ::Binda::Api::Types::TextType do
|
22
|
+
argument :slug, !context.types.String
|
23
|
+
|
24
|
+
resolve ->(obj, args, ctx) {
|
25
|
+
begin
|
26
|
+
obj.get_string(args[:slug])
|
27
|
+
rescue ArgumentError
|
28
|
+
""
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
context.field :get_text, ::Binda::Api::Types::TextType do
|
34
|
+
argument :slug, !context.types.String
|
35
|
+
|
36
|
+
resolve ->(obj, args, ctx) {
|
37
|
+
begin
|
38
|
+
obj.get_text(args[:slug])
|
39
|
+
rescue ArgumentError
|
40
|
+
""
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
context.field :get_radio_choice, ::Binda::Api::Types::RadioType do
|
46
|
+
argument :slug, !context.types.String
|
47
|
+
|
48
|
+
resolve ->(obj, args, ctx) {
|
49
|
+
obj.get_radio_choice(args[:slug])
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
context.field :get_checkbox_choices, ::Binda::Api::Types::CheckboxType.to_list_type do
|
54
|
+
argument :slug, !context.types.String
|
55
|
+
|
56
|
+
resolve ->(obj, args, ctx) {
|
57
|
+
obj.get_checkbox_choices(args[:slug])
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
context.field :get_selection_choice, ::Binda::Api::Types::SelectionType do
|
62
|
+
argument :slug, !context.types.String
|
63
|
+
|
64
|
+
resolve ->(obj, args, ctx) {
|
65
|
+
obj.get_selection_choice(args[:slug])
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
context.field :get_image, ::Binda::Api::Types::ImageType do
|
70
|
+
argument :slug, !context.types.String
|
71
|
+
|
72
|
+
resolve ->(obj, args, ctx) {
|
73
|
+
obj.images.find{ |t| t.field_setting_id == ::Binda::FieldSetting.get_id( args[:slug] ) }
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
context.field :get_audio, ::Binda::Api::Types::AudioType do
|
78
|
+
argument :slug, !context.types.String
|
79
|
+
|
80
|
+
resolve ->(obj, args, ctx) {
|
81
|
+
obj.audios.find{ |t| t.field_setting_id == ::Binda::FieldSetting.get_id( args[:slug] ) }
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
context.field :get_video, ::Binda::Api::Types::VideoType do
|
86
|
+
argument :slug, !context.types.String
|
87
|
+
|
88
|
+
resolve ->(obj, args, ctx) {
|
89
|
+
obj.videos.find{ |t| t.field_setting_id == ::Binda::FieldSetting.get_id( args[:slug] ) }
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
context.field :get_svg, ::Binda::Api::Types::SvgType do
|
94
|
+
argument :slug, !context.types.String
|
95
|
+
|
96
|
+
resolve ->(obj, args, ctx) {
|
97
|
+
obj.svgs.find{ |t| t.field_setting_id == ::Binda::FieldSetting.get_id( args[:slug] ) }
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
context.field :repeaters, ::Binda::Api::Types::RepeaterType.to_list_type do
|
102
|
+
argument :slug, !context.types.String
|
103
|
+
|
104
|
+
resolve ->(obj, args, ctx) {
|
105
|
+
obj.repeaters.order("binda_repeaters.position").select{ |t| t.field_setting_id == ::Binda::FieldSetting.get_id( args[:slug] ) }
|
106
|
+
}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,243 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: binda-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marco Crepaldi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: binda
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.9
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.9
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: graphql
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.0.pre11
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.0.pre11
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: graphiql-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-cors
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pg
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.21'
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '1.0'
|
93
|
+
type: :runtime
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0.21'
|
100
|
+
- - "<"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rspec-rails
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '3.5'
|
110
|
+
- - "<"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '3.8'
|
113
|
+
type: :development
|
114
|
+
prerelease: false
|
115
|
+
version_requirements: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '3.5'
|
120
|
+
- - "<"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '3.8'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: byebug
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '10.0'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '10.0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: factory_bot_rails
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '4.8'
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - "~>"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '4.8'
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
name: database_cleaner
|
153
|
+
requirement: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '1.6'
|
158
|
+
- - "<"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '2'
|
161
|
+
type: :development
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '1.6'
|
168
|
+
- - "<"
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '2'
|
171
|
+
description: ''
|
172
|
+
email:
|
173
|
+
- marco.crepaldi@gmail.com
|
174
|
+
executables: []
|
175
|
+
extensions: []
|
176
|
+
extra_rdoc_files: []
|
177
|
+
files:
|
178
|
+
- MIT-LICENSE
|
179
|
+
- README.md
|
180
|
+
- Rakefile
|
181
|
+
- app/controllers/binda/api/application_controller.rb
|
182
|
+
- app/controllers/graphql_controller.rb
|
183
|
+
- app/graphql/binda/api/fields/board_by_slug_field.rb
|
184
|
+
- app/graphql/binda/api/fields/component_by_slug_field.rb
|
185
|
+
- app/graphql/binda/api/fields/components_by_structure_field.rb
|
186
|
+
- app/graphql/binda/api/fields/components_field.rb
|
187
|
+
- app/graphql/binda/api/fields/repeaters_field.rb
|
188
|
+
- app/graphql/binda/api/fields/structures_field.rb
|
189
|
+
- app/graphql/binda/api/resolvers/board_by_slug_resolver.rb
|
190
|
+
- app/graphql/binda/api/resolvers/component_by_slug_resolver.rb
|
191
|
+
- app/graphql/binda/api/resolvers/components_by_structure_resolver.rb
|
192
|
+
- app/graphql/binda/api/resolvers/components_resolver.rb
|
193
|
+
- app/graphql/binda/api/resolvers/repeaters_resolver.rb
|
194
|
+
- app/graphql/binda/api/resolvers/structures_resolver.rb
|
195
|
+
- app/graphql/binda/api/schema.rb
|
196
|
+
- app/graphql/binda/api/types/audio_type.rb
|
197
|
+
- app/graphql/binda/api/types/board_type.rb
|
198
|
+
- app/graphql/binda/api/types/checkbox_type.rb
|
199
|
+
- app/graphql/binda/api/types/component_type.rb
|
200
|
+
- app/graphql/binda/api/types/image_type.rb
|
201
|
+
- app/graphql/binda/api/types/mutation_type.rb
|
202
|
+
- app/graphql/binda/api/types/query_type.rb
|
203
|
+
- app/graphql/binda/api/types/radio_type.rb
|
204
|
+
- app/graphql/binda/api/types/repeater_type.rb
|
205
|
+
- app/graphql/binda/api/types/selection_type.rb
|
206
|
+
- app/graphql/binda/api/types/structure_type.rb
|
207
|
+
- app/graphql/binda/api/types/svg_type.rb
|
208
|
+
- app/graphql/binda/api/types/text_type.rb
|
209
|
+
- app/graphql/binda/api/types/video_type.rb
|
210
|
+
- app/helpers/binda/api/application_helper.rb
|
211
|
+
- app/models/binda/api/application_record.rb
|
212
|
+
- config/database.yml.travis
|
213
|
+
- config/routes.rb
|
214
|
+
- lib/binda/api.rb
|
215
|
+
- lib/binda/api/engine.rb
|
216
|
+
- lib/binda/api/fields.rb
|
217
|
+
- lib/binda/api/version.rb
|
218
|
+
- lib/tasks/binda/api_tasks.rake
|
219
|
+
homepage: http://lacolonia.studio
|
220
|
+
licenses:
|
221
|
+
- MIT
|
222
|
+
metadata: {}
|
223
|
+
post_install_message:
|
224
|
+
rdoc_options: []
|
225
|
+
require_paths:
|
226
|
+
- lib
|
227
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
228
|
+
requirements:
|
229
|
+
- - ">="
|
230
|
+
- !ruby/object:Gem::Version
|
231
|
+
version: '0'
|
232
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
requirements: []
|
238
|
+
rubyforge_project:
|
239
|
+
rubygems_version: 2.6.12
|
240
|
+
signing_key:
|
241
|
+
specification_version: 4
|
242
|
+
summary: Binda plugin that adds a GraphQL api to your applicaiton
|
243
|
+
test_files: []
|