Types Overview
View SourceGreenFairy provides a clean DSL for defining all GraphQL type kinds. Each type kind has its own module and follows the "one module = one type" principle.
Type Kinds
| Kind | Module | Guide |
|---|---|---|
| Object Types | GreenFairy.Type | Object Types |
| Interfaces | GreenFairy.Interface | Interfaces |
| Input Types | GreenFairy.Input | Input Types |
| Enums | GreenFairy.Enum | Enums |
| Unions | GreenFairy.Union | Unions |
| Scalars | GreenFairy.Scalar | Scalars |
Directory Structure
Organize types by kind:
lib/my_app/graphql/
├── schema.ex # Main schema
├── types/ # Object types
├── interfaces/ # Interfaces
├── inputs/ # Input types
├── enums/ # Enums
├── unions/ # Unions
├── scalars/ # Custom scalars
├── queries/ # Query operations
├── mutations/ # Mutation operations
└── resolvers/ # Resolver logicType References
Use module references for non-builtin types to enable auto-discovery:
alias MyApp.GraphQL.Types
alias MyApp.GraphQL.Enums
field :posts, list_of(Types.Post)
field :status, Enums.UserStatusUse atoms only for built-in scalars: :id, :string, :integer, :float, :boolean, :datetime.
Common Module Functions
All GreenFairy type modules export:
| Function | Description |
|---|---|
__green_fairy_kind__/0 | Returns the type kind (:object, :interface, etc.) |
__green_fairy_identifier__/0 | Returns the snake_case identifier |
__green_fairy_definition__/0 | Returns the full definition map |
Naming Conventions
| GraphQL Name | Elixir Identifier |
|---|---|
User | :user |
CreateUserInput | :create_user_input |
UserRole | :user_role |
The identifier is automatically derived from the GraphQL name using snake_case.
Detailed Guides
- Object Types - Fields, resolvers, batch loading, associations
- Interfaces - Shared fields, automatic type resolution
- Input Types - Mutation arguments, validation
- Enums - Value definitions, mappings
- Unions - Polymorphic returns
- Scalars - Custom parsing/serialization
Related Guides
- Operations - Queries, mutations, subscriptions
- Relationships - Associations and DataLoader
- Connections - Relay-style pagination
- Authorization - Field-level access control
- CQL - Automatic filtering and sorting