GreenFairy.Interface (GreenFairy v0.3.0)
View SourceDefines a GraphQL interface type with a clean DSL.
Usage
defmodule MyApp.GraphQL.Interfaces.Node do
use GreenFairy.Interface
interface "Node" do
@desc "A globally unique identifier"
field :id, :id, null: false
end
endThe resolve_type function is automatically generated based on types that
implement this interface using implements/1. Each implementing type must
specify its backing struct via type "Name", struct: Module.
Manual resolve_type
You can override the auto-generated resolve_type if needed:
interface "Node" do
field :id, :id, null: false
resolve_type fn
%MyApp.User{} -> :user
%MyApp.Post{} -> :post
_ -> nil
end
end
Summary
Functions
Defines a GraphQL interface.
Controls whether this interface or its fields appear in introspection results.
See GreenFairy.Type.visible/1 for details.
Functions
Defines a GraphQL interface.
If no resolve_type is provided, one will be auto-generated using
the registry of types that implement this interface.
Examples
interface "Node" do
field :id, :id, null: false
end
Controls whether this interface or its fields appear in introspection results.
See GreenFairy.Type.visible/1 for details.