Skip to content

Commit

Permalink
Handle values via attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryseed committed Jan 14, 2021
1 parent 4f8e129 commit 31327dd
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 64 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
- Feature: Support for the [`repeatable` directive](https://github.com/absinthe-graphql/absinthe/pull/999)
- Feature: Enable [rendering](https://github.com/absinthe-graphql/absinthe/pull/1010) of Type System Directives in SDL based schemas.
- Feature: Correctly match [Introspection type specs](https://github.com/absinthe-graphql/absinthe/pull/1017)
- Bug Fix: Restore dynamic description support [comprehensively fixed](https://github.com/absinthe-graphql/absinthe/pull/1005) (Note: the `description`s are evaluated once --- at compile time)
- Bug Fix: Restore dynamic default_value support [comprehensively fixed](https://github.com/absinthe-graphql/absinthe/pull/1026) (Note: the `default_value`s evaluated once --- at compile time)
- Bug Fix: Restore dynamic [description support](https://github.com/absinthe-graphql/absinthe/pull/1005) (Note: the `description`s are evaluated once --- at compile time)
- Bug Fix: Restore dynamic [default_value support](https://github.com/absinthe-graphql/absinthe/pull/1026) (Note: the `default_value`s evaluated once --- at compile time)
- Bug Fix: Restore dynamic [Enum value support](https://github.com/absinthe-graphql/absinthe/pull/1023) (Note: the `value` is evaluated once --- at compile time)
- Bug Fix: [Interface nullability](https://github.com/absinthe-graphql/absinthe/pull/1009) corrections
- Bug Fix: Fix [field listing for Inputs](https://github.com/absinthe-graphql/absinthe/pull/1015) that import fields
- Bug Fix: Properly [trim all descriptions](https://github.com/absinthe-graphql/absinthe/pull/1014) no matter the mechanism used to specify them
Expand Down
3 changes: 3 additions & 0 deletions lib/absinthe/blueprint/schema/enum_type_definition.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ defmodule Absinthe.Blueprint.Schema.EnumTypeDefinition do

{Map.fetch!(value_def, key), value}

# Values defined via dynamic function calls don't yet get converted
# into proper Blueprints, but it works for now. This will get refactored
# in the future as we build out a general solution for dynamic values.
raw_value ->
name = raw_value |> to_string() |> String.upcase()

Expand Down
34 changes: 34 additions & 0 deletions lib/absinthe/introspection/directive_location.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
defmodule Absinthe.Introspection.DirectiveLocation do
@moduledoc false

# https://spec.graphql.org/draft/#sec-Schema-Introspection

@executable_directive_locations [
:query,
:mutation,
:subscription,
:field,
:fragment_definition,
:fragment_spread,
:inline_fragment,
:variable_definition
]
@type_system_directive_locations [
:schema,
:scalar,
:object,
:field_definition,
:argument_definition,
:interface,
:union,
:enum,
:enum_value,
:input_object,
:input_field_definition
]

def values do
@executable_directive_locations ++
@type_system_directive_locations
end
end
13 changes: 13 additions & 0 deletions lib/absinthe/introspection/type_kind.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ defmodule Absinthe.Introspection.TypeKind do
| :non_null

@callback kind() :: type_kind()

def values do
[
:scalar,
:object,
:interface,
:union,
:enum,
:input_object,
:list,
:non_null
]
end
end
26 changes: 1 addition & 25 deletions lib/absinthe/phase/schema/validation/directives_must_be_valid.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Absinthe.Phase.Schema.Validation.DirectivesMustBeValid do
alias Absinthe.Blueprint

@spec_link "https://spec.graphql.org/draft/#sec-Type-System.Directives"
@directive_locations Absinthe.Introspection.DirectiveLocation.values()

@doc """
Run the validation.
Expand Down Expand Up @@ -33,31 +34,6 @@ defmodule Absinthe.Phase.Schema.Validation.DirectivesMustBeValid do
end)
end

@executable_directive_locations [
:query,
:mutation,
:subscription,
:field,
:fragment_definition,
:fragment_spread,
:inline_fragment,
:variable_definition
]
@type_system_directive_locations [
:schema,
:scalar,
:object,
:field_definition,
:argument_definition,
:interface,
:union,
:enum,
:enum_value,
:input_object,
:input_field_definition
]
@directive_locations @executable_directive_locations ++ @type_system_directive_locations

defp validate_location(directive, location) when location in @directive_locations do
directive
end
Expand Down
7 changes: 1 addition & 6 deletions lib/absinthe/schema/notation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1101,12 +1101,7 @@ defmodule Absinthe.Schema.Notation do
defp handle_enum_attrs(attrs, env) do
attrs
|> expand_ast(env)
|> Keyword.update(:values, [], fn values ->
Enum.map(values, fn ident ->
value_attrs = handle_enum_value_attrs(ident, [], env)
struct!(Schema.EnumValueDefinition, value_attrs)
end)
end)
|> Keyword.update(:values, [], &[wrap_in_unquote(&1)])
|> Keyword.update(:description, nil, &wrap_in_unquote/1)
end

Expand Down
33 changes: 2 additions & 31 deletions lib/absinthe/type/built_ins/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,39 +99,10 @@ defmodule Absinthe.Type.BuiltIns.Introspection do
end

enum :__type_kind,
values: [
:scalar,
:object,
:interface,
:union,
:enum,
:input_object,
:list,
:non_null
]
values: Absinthe.Introspection.TypeKind.values()

enum :__directive_location,
values: [
:query,
:mutation,
:subscription,
:field,
:fragment_definition,
:fragment_spread,
:inline_fragment,
:variable_definition,
:schema,
:scalar,
:object,
:field_definition,
:argument_definition,
:interface,
:union,
:enum,
:enum_value,
:input_object,
:input_field_definition
]
values: Absinthe.Introspection.DirectiveLocation.values()

object :__type do
description "Represents scalars, interfaces, object types, unions, enums in the system"
Expand Down

0 comments on commit 31327dd

Please sign in to comment.