Sha256: b06e8060f7051387cbc6ca08f1d89af1ea097c107cd028754e62f93351090f05

Contents?: true

Size: 1.7 KB

Versions: 6

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# ! The following examples are used together with
# ! https://github.com/sushie1984/rails-graphql-server
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

uri = 'http://rails-graphql-server.herokuapp.com/api/graphql'
GraphqlConnector.configure do |config|
  config.add_server(name: 'RailsGraphqlServer', uri: uri, headers: {})
end

# Service class for fetching department data
class Department
  extend GraphqlConnector::RailsGraphqlServer::Query

  add_query all: :departments, returns: [:id, :name, employees: [:yearlySalary]]

  add_query by_id: :departments,
            params: [:id],
            returns: [:id, :name, employees: [:yearlySalary]]

  add_raw_query all_raw: 'query {
                            departments {
                              id name employees { yearlySalary }
                            }
                          }'

  add_raw_query by_id_raw: 'query departments($id: [ID!]) {
                              departments(id: $id) {
                                name employees { name }
                              }
                            }',
                params: [:id]

  # We use a nested 'input' as of convention for
  # https://github.com/sushie1984/rails-graphql-server/blob/master/app/graphql/input_objects/department_attributes.rb
  add_mutation create: :createDepartment,
               params: :input,
               returns: [department: %i[id name location]]
end

Department.all

Department.by_id(id: %w[1 2])

Department.all_raw

Department.by_id_raw(id: %w[1 2])

Department.create(input: { attributes: { name: 'One', location: 'Berlin' } })

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
graphql_connector-2.0.0 examples/departments_service_class_examples.rb
graphql_connector-1.4.0 examples/departments_service_class_examples.rb
graphql_connector-1.3.1 examples/departments_service_class_examples.rb
graphql_connector-1.3.0 examples/departments_service_class_examples.rb
graphql_connector-1.2.1 examples/departments_service_class_examples.rb
graphql_connector-1.2.0 examples/departments_service_class_examples.rb