JetPluginSDK.API.GraphQL behaviour (JetPluginSDK v0.1.2)

This module helps to define the GraphQL API schema for Jet plugins.

define schema

defmodule MySchema do
  use JetPluginSDK.API.GraphQL,
    query_fields: [
      do:
        field :some_query, type: :string do
          resolve &__MODULE__.some_query/2
        end
    ],
    mutation_fields: [
      do:
        field :some_mutation, type: :string do
          resolve &__MODULE__.some_mutation/2
        end
    ]

  # define input_object for plugin_config
  plugin_config do
    field :foo, :string
  end

  @impl JetPluginSDK.API.GraphQL
  def initialize(_args, _resolution) do
    # implement initialize here
  end

  @impl JetPluginSDK.API.GraphQL
  def install(_args, _resolution) do
    # implement install here
  end

  @impl JetPluginSDK.API.GraphQL
  def update(_args, _resolution) do
  # implement update here
  end

  @impl JetPluginSDK.API.GraphQL
  def uninstall(_args, _resolution) do
    # implement uninstall here
  end

  @impl JetPluginSDK.API.GraphQL
  def health_check(_args, _resolution) do
    # implement health check here
  end
end

generate callbacks via setting tenant_module

defmodule MySchema do
  use JetPluginSDK.API.GraphQL,
    tenant_module: MyApp.Tenant

  plugin_config do
    field :foo, :string
  end
end

Summary

Functions

Jet should call jet_plugin_install and jet_plugin_update with config defined in this type.

Types

Link to this type

callback_response()

Link to this type

callback_response_async()

@type callback_response_async() :: %{
  optional(:message) => String.t(),
  optional(:extensions) => String.t(),
  __callback_resp_type__: :async
}
Link to this type

callback_response_error()

@type callback_response_error() :: %{
  optional(:message) => String.t(),
  optional(:extensions) => String.t(),
  __callback_resp_type__: :error,
  invalid_argument: String.t(),
  expected: String.t()
}
Link to this type

callback_response_ok()

@type callback_response_ok() :: %{
  optional(:message) => String.t(),
  optional(:extensions) => String.t(),
  __callback_resp_type__: :ok
}
Link to this type

capability()

@type capability() :: database_capability()
Link to this type

database_capability()

@type database_capability() :: %{__capability_type__: :database, enable: boolean()}
Link to this type

initialize_response()

@type initialize_response() :: manifest() | callback_response_async()
@type manifest() :: %{
  optional(:api_endpoint) => String.t(),
  optional(:description) => String.t(),
  version: String.t(),
  capabilities: [capability()]
}

Callbacks

Link to this callback

health_check(args, resolution)

@callback health_check(
  args :: %{},
  resolution()
) :: {:ok, callback_response()} | {:error, term()}
Link to this callback

initialize(args, resolution)

@callback initialize(
  args :: %{},
  resolution()
) :: {:ok, initialize_response()} | {:error, term()}
Link to this callback

install(args, resolution)

@callback install(
  args :: %{
    project_id: String.t(),
    env_id: String.t(),
    instance_id: String.t(),
    config: JetPluginSDK.Tenant.config(),
    capabilities: JetPluginSDK.Tenant.capabilities()
  },
  resolution()
) :: {:ok, callback_response()} | {:error, term()}
Link to this callback

uninstall(args, resolution)

@callback uninstall(
  args :: %{project_id: String.t(), env_id: String.t(), instance_id: String.t()},
  resolution()
) ::
  {:ok, callback_response_ok() | callback_response_async()} | {:error, term()}
Link to this callback

update(args, resolution)

@callback update(
  args :: %{
    project_id: String.t(),
    env_id: String.t(),
    instance_id: String.t(),
    config: JetPluginSDK.Tenant.config(),
    capabilities: JetPluginSDK.Tenant.capabilities()
  },
  resolution()
) :: {:ok, callback_response()} | {:error, term()}

Functions

Link to this macro

plugin_config(block)

(macro)

Jet should call jet_plugin_install and jet_plugin_update with config defined in this type.

  plugin_config do
    field :foo, :string
  end