Skip to content

Commit

Permalink
feat(hubspot): Add GraphQL for hubspot connection (#2591)
Browse files Browse the repository at this point in the history
## Roadmap Task

👉  https://getlago.canny.io/feature-requests/p/integration-with-hubspot

## Context

Integration with HubSpot to import customers, subscriptions and
invoices.

## Description

This PR adds GraphQL needed for Hubspot connection: Enum, Types, Inputs,
Mutations and Resolver.

---------

Co-authored-by: Miguel Pinto <[email protected]>
  • Loading branch information
ivannovosad and brunomiguelpinto authored Sep 18, 2024
1 parent a66c402 commit c1951e0
Show file tree
Hide file tree
Showing 16 changed files with 865 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/graphql/mutations/integrations/hubspot/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Mutations
module Integrations
module Hubspot
class Create < BaseMutation
include AuthenticableApiUser
include RequiredOrganization

REQUIRED_PERMISSION = 'organization:integrations:create'

graphql_name 'CreateHubspotIntegration'
description 'Create Hubspot integration'

input_object_class Types::Integrations::Hubspot::CreateInput

type Types::Integrations::Hubspot

def resolve(**args)
result = ::Integrations::Hubspot::CreateService
.new(params: args.merge(organization_id: current_organization.id))
.call

result.success? ? result.integration : result_error(result)
end
end
end
end
end
28 changes: 28 additions & 0 deletions app/graphql/mutations/integrations/hubspot/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Mutations
module Integrations
module Hubspot
class Update < BaseMutation
include AuthenticableApiUser
include RequiredOrganization

REQUIRED_PERMISSION = 'organization:integrations:update'

graphql_name 'UpdateHubspotIntegration'
description 'Update Hubspot integration'

input_object_class Types::Integrations::Hubspot::UpdateInput

type Types::Integrations::Hubspot

def resolve(**args)
integration = current_organization.integrations.find_by(id: args[:id])
result = ::Integrations::Hubspot::UpdateService.call(integration:, params: args)

result.success? ? result.integration : result_error(result)
end
end
end
end
end
2 changes: 2 additions & 0 deletions app/graphql/resolvers/integrations_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def integration_type(type)
'Integrations::AnrokIntegration'
when 'xero'
'Integrations::XeroIntegration'
when 'hubspot'
'Integrations::HubspotIntegration'
else
raise(NotImplementedError)
end
Expand Down
18 changes: 18 additions & 0 deletions app/graphql/types/integrations/hubspot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Types
module Integrations
class Hubspot < Types::BaseObject
graphql_name 'HubspotIntegration'

field :code, String, null: false
field :connection_id, ID, null: false
field :default_targeted_object, Types::Integrations::Hubspot::TargetedObjectsEnum, null: false
field :id, ID, null: false
field :name, String, null: false
field :private_app_token, String, null: false
field :sync_invoices, Boolean
field :sync_subscriptions, Boolean
end
end
end
20 changes: 20 additions & 0 deletions app/graphql/types/integrations/hubspot/create_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Types
module Integrations
class Hubspot
class CreateInput < Types::BaseInputObject
graphql_name 'CreateHubspotIntegrationInput'

argument :code, String, required: true
argument :name, String, required: true

argument :connection_id, String, required: true
argument :default_targeted_object, Types::Integrations::Hubspot::TargetedObjectsEnum, required: true
argument :private_app_token, String, required: true
argument :sync_invoices, Boolean, required: false
argument :sync_subscriptions, Boolean, required: false
end
end
end
end
13 changes: 13 additions & 0 deletions app/graphql/types/integrations/hubspot/targeted_objects_enum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Types
module Integrations
class Hubspot
class TargetedObjectsEnum < Types::BaseEnum
::Integrations::HubspotIntegration::TARGETED_OBJECTS.each do |type|
value type
end
end
end
end
end
22 changes: 22 additions & 0 deletions app/graphql/types/integrations/hubspot/update_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Types
module Integrations
class Hubspot
class UpdateInput < Types::BaseInputObject
graphql_name 'UpdateHubspotIntegrationInput'

argument :id, ID, required: false

argument :code, String, required: false
argument :name, String, required: false

argument :connection_id, String, required: false
argument :default_targeted_object, Types::Integrations::Hubspot::TargetedObjectsEnum, required: false
argument :private_app_token, String, required: false
argument :sync_invoices, Boolean, required: false
argument :sync_subscriptions, Boolean, required: false
end
end
end
end
3 changes: 3 additions & 0 deletions app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class MutationType < Types::BaseObject
field :create_xero_integration, mutation: Mutations::Integrations::Xero::Create
field :update_xero_integration, mutation: Mutations::Integrations::Xero::Update

field :create_hubspot_integration, mutation: Mutations::Integrations::Hubspot::Create
field :update_hubspot_integration, mutation: Mutations::Integrations::Hubspot::Update

field :okta_accept_invite, mutation: Mutations::Auth::Okta::AcceptInvite
field :okta_authorize, mutation: Mutations::Auth::Okta::Authorize
field :okta_login, mutation: Mutations::Auth::Okta::Login
Expand Down
71 changes: 71 additions & 0 deletions schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c1951e0

Please sign in to comment.