GreenFairy.BuiltIns.Node (GreenFairy v0.3.0)

View Source

Built-in Relay Node interface.

This interface provides the standard Relay Global Object Identification pattern with a globally unique ID field.

Usage

Types can implement this interface:

defmodule MyApp.GraphQL.Types.User do
  use GreenFairy.Type
  import GreenFairy.Relay.Field

  type "User", struct: MyApp.User do
    implements GreenFairy.BuiltIns.Node

    global_id :id  # Generates globally unique ID
    field :email, :string
  end
end

With Custom Node Resolution

For the node(id: ID!) query to work, define a node resolver:

type "User", struct: MyApp.User do
  implements GreenFairy.BuiltIns.Node

  node_resolver fn id, _ctx ->
    MyApp.Accounts.get_user(id)
  end

  global_id :id
  field :email, :string
end

Summary

Functions

Finds the GraphQL type identifier for a given Elixir struct.

Functions

find_type_for_struct(struct, schema)

Finds the GraphQL type identifier for a given Elixir struct.

This uses the GreenFairy.Registry to look up types by their struct.