-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b585033
commit c6db0fc
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
defmodule AshGraphql.Type do | ||
@moduledoc """ | ||
Callbacks used to enrich types with GraphQL-specific metadata. | ||
""" | ||
|
||
@doc """ | ||
Sets the name of the graphql type for a given Ash type. For example: `:weekday`. | ||
This will do different things depending on the type you're adding it to. | ||
## Regular Types | ||
This expresses that you will define a custom type for representing this in your graphql | ||
## NewTypes | ||
If it is a subtype of a union, or map/keyword with `fields` the type will be *created* with that name. | ||
So you can use this to decide what it will be named. Otherwise, it behaves as stated above for | ||
regular types. | ||
""" | ||
@callback graphql_type(Ash.Type.constraints()) :: :atom | ||
|
||
@doc """ | ||
Sets the name of the graphql input type for a given Ash type. For example: `:weekday`. | ||
This will do different things depending on the type you're adding it to. | ||
## Regular Types | ||
This expresses that you will define a custom type for representing this input in your graphql | ||
## NewTypes | ||
If it is a subtype of a union, or map/keyword with `fields` the type will be *created* with that name. | ||
So you can use this to decide what it will be named. Otherwise, it behaves as stated above for | ||
regular types. | ||
""" | ||
@callback graphql_input_type(Ash.Type.constraints()) :: :atom | ||
|
||
@doc """ | ||
Used for `Ash.Type.Enum` to rename individual values. For example: | ||
```elixir | ||
defmodule MyEnum do | ||
use Ash.Type.Enum, values: [:foo, :bar, :baz] | ||
def graphql_rename_value(:baz), do: :buz | ||
def graphql_rename_value(other), do: other | ||
end | ||
``` | ||
""" | ||
@callback graphql_rename_value(Ash.Type.constraints()) :: String.t() | :atom | ||
|
||
@doc """ | ||
Used for map/embedded types embedded in unions, to avoid nesting them in a key by their name. | ||
See [the unions guide](/documentation/how_to/use-unions-with-graphql.md) for more. | ||
""" | ||
@callback graphql_unnested_unions(Ash.Type.constraints()) :: :atom | ||
|
||
@optional_callbacks graphql_type: 1, | ||
graphql_input_type: 1, | ||
graphql_rename_value: 1, | ||
graphql_unnested_unions: 1 | ||
end |