Add graphql root types

This commit is contained in:
Paul Chavard 2018-11-19 21:06:13 +01:00
parent 52e84f2ffe
commit e06051bc96
3 changed files with 34 additions and 0 deletions

View file

@ -3,6 +3,9 @@ class Api::V2::Schema < GraphQL::Schema
max_complexity 300
max_depth 15
query Types::QueryType
mutation Types::MutationType
def self.unauthorized_object(error)
# Add a top-level error to the response instead of returning nil:
raise GraphQL::ExecutionError.new("An object of type #{error.type.graphql_name} was hidden due to permissions", extensions: { code: :unauthorized })

View file

@ -0,0 +1,4 @@
module Types
class MutationType < Types::BaseObject
end
end

View file

@ -0,0 +1,27 @@
module Types
class QueryType < Types::BaseObject
field :demarche, DemarcheType, null: false, description: "Informations concernant une démarche." do
argument :number, ID, "Numéro de la démarche.", required: true
end
field :dossier, DossierType, null: false, description: "Informations sur un dossier d'une démarche." do
argument :number, ID, "Numéro du dossier.", required: true
end
def demarche(number:)
Procedure.for_api_v2.find(number)
rescue => e
raise GraphQL::ExecutionError.new(e.message, extensions: { code: :not_found })
end
def dossier(number:)
Dossier.for_api_v2.find(number)
rescue => e
raise GraphQL::ExecutionError.new(e.message, extensions: { code: :not_found })
end
def self.accessible?(context)
context[:token] || context[:administrateur_id]
end
end
end