GreenFairy.Union (GreenFairy v0.3.0)

View Source

Defines a GraphQL union type with a clean DSL.

Usage

defmodule MyApp.GraphQL.Unions.SearchResult do
  use GreenFairy.Union

  union "SearchResult" do
    types [:user, :post, :comment]

    resolve_type fn
      %MyApp.User{}, _ -> :user
      %MyApp.Post{}, _ -> :post
      %MyApp.Comment{}, _ -> :comment
      _, _ -> nil
    end
  end
end

Options

  • :description - Description of the union type (can also use @desc)

Summary

Functions

Defines a GraphQL union type.

Functions

union(name, opts \\ [], list)

(macro)

Defines a GraphQL union type.

Examples

union "SearchResult" do
  types [:user, :post, :comment]

  resolve_type fn
    %MyApp.User{}, _ -> :user
    %MyApp.Post{}, _ -> :post
    _, _ -> nil
  end
end