swell/schema

Types

GraphQL Argument

pub opaque type Argument

Resolver context - will contain request context, data loaders, etc.

pub type Context {
  Context(
    data: option.Option(value.Value),
    arguments: dict.Dict(String, value.Value),
    variables: dict.Dict(String, value.Value),
  )
}

Constructors

GraphQL Enum Value

pub opaque type EnumValue

GraphQL Field

pub opaque type Field

GraphQL Input Field (for InputObject types)

pub opaque type InputField

Field resolver function type

pub type Resolver =
  fn(Context) -> Result(value.Value, String)

GraphQL Schema

pub opaque type Schema

GraphQL Type

pub opaque type Type

Values

pub fn argument(
  name: String,
  arg_type: Type,
  description: String,
  default_value: option.Option(value.Value),
) -> Argument
pub fn argument_description(arg: Argument) -> String

Get argument description

pub fn argument_name(arg: Argument) -> String

Get argument name

pub fn argument_type(arg: Argument) -> Type

Get argument type

pub fn boolean_type() -> Type
pub fn context(data: option.Option(value.Value)) -> Context

Helper to create a context without arguments or variables

pub fn context_with_variables(
  data: option.Option(value.Value),
  variables: dict.Dict(String, value.Value),
) -> Context

Helper to create a context with variables

pub fn enum_type(
  name: String,
  description: String,
  values: List(EnumValue),
) -> Type
pub fn enum_value(name: String, description: String) -> EnumValue
pub fn enum_value_description(enum_value: EnumValue) -> String

Get enum value description

pub fn enum_value_name(enum_value: EnumValue) -> String

Get enum value name

pub fn field(
  name: String,
  field_type: Type,
  description: String,
  resolver: fn(Context) -> Result(value.Value, String),
) -> Field
pub fn field_arguments(field: Field) -> List(Argument)

Get field arguments

pub fn field_description(field: Field) -> String

Get field description

pub fn field_name(f: Field) -> String
pub fn field_type(field: Field) -> Type

Get the type of a field

pub fn field_with_args(
  name: String,
  field_type: Type,
  description: String,
  arguments: List(Argument),
  resolver: fn(Context) -> Result(value.Value, String),
) -> Field
pub fn float_type() -> Type
pub fn get_argument(
  ctx: Context,
  name: String,
) -> option.Option(value.Value)

Helper to get an argument value from context

pub fn get_enum_values(t: Type) -> List(EnumValue)

Get all enum values from an EnumType

pub fn get_field(
  t: Type,
  field_name: String,
) -> option.Option(Field)
pub fn get_fields(t: Type) -> List(Field)

Get all fields from an ObjectType

pub fn get_input_fields(t: Type) -> List(InputField)

Get all input fields from an InputObjectType

pub fn get_mutation_type(s: Schema) -> option.Option(Type)
pub fn get_possible_types(t: Type) -> List(Type)

Get the possible types from a union

pub fn get_subscription_type(s: Schema) -> option.Option(Type)
pub fn get_union_type_resolver(
  t: Type,
) -> fn(Context) -> Result(String, String)

Get the type resolver function from a union type. The type resolver is called at runtime to determine which concrete type a union value represents, based on the data in the context. Returns a default resolver that always errors for non-union types. This is primarily used internally for union type normalization.

pub fn get_variable(
  ctx: Context,
  name: String,
) -> option.Option(value.Value)

Helper to get a variable value from context

pub fn id_type() -> Type
pub fn inner_type(t: Type) -> option.Option(Type)

Get the inner type from a wrapping type (List or NonNull)

pub fn input_field(
  name: String,
  field_type: Type,
  description: String,
  default_value: option.Option(value.Value),
) -> InputField
pub fn input_field_description(input_field: InputField) -> String

Get input field description

pub fn input_field_name(input_field: InputField) -> String

Get input field name

pub fn input_field_type(input_field: InputField) -> Type

Get input field type

pub fn input_object_type(
  name: String,
  description: String,
  fields: List(InputField),
) -> Type
pub fn int_type() -> Type
pub fn is_enum(t: Type) -> Bool

Check if type is an enum

pub fn is_input_object(t: Type) -> Bool
pub fn is_list(t: Type) -> Bool
pub fn is_non_null(t: Type) -> Bool
pub fn is_object(t: Type) -> Bool

Check if type is an object

pub fn is_scalar(t: Type) -> Bool

Check if type is a scalar

pub fn is_union(t: Type) -> Bool

Check if type is a union

pub fn list_type(inner_type: Type) -> Type
pub fn named_type_name(t: Type) -> String

Get the named (base) type name, unwrapping List and NonNull wrappers. This is used for fragment type condition matching and __typename where we need the concrete type name without modifiers.

pub fn non_null(inner_type: Type) -> Type
pub fn object_type(
  name: String,
  description: String,
  fields: List(Field),
) -> Type
pub fn query_type(s: Schema) -> Type
pub fn resolve_field(
  field: Field,
  ctx: Context,
) -> Result(value.Value, String)
pub fn resolve_union_type(
  t: Type,
  ctx: Context,
) -> Result(Type, String)

Resolve a union type to its concrete type using the type resolver

pub fn resolve_union_type_with_registry(
  t: Type,
  ctx: Context,
  type_registry: dict.Dict(String, Type),
) -> Result(Type, String)

Resolve a union type using a canonical type registry This looks up the concrete type by name from the registry instead of from the union’s possible_types, ensuring we get the most complete type definition

pub fn schema(
  query_type: Type,
  mutation_type: option.Option(Type),
) -> Schema
pub fn schema_with_subscriptions(
  query_type: Type,
  mutation_type: option.Option(Type),
  subscription_type: option.Option(Type),
) -> Schema
pub fn string_type() -> Type
pub fn type_description(t: Type) -> String
pub fn type_kind(t: Type) -> String

Get the kind of a type as a string for introspection

pub fn type_name(t: Type) -> String
pub fn union_type(
  name: String,
  description: String,
  possible_types: List(Type),
  type_resolver: fn(Context) -> Result(String, String),
) -> Type
Search Document