-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply type system directives in macro based schemas #1140
Merged
benwilson512
merged 4 commits into
absinthe-graphql:master
from
maartenvanvliet:issues/type-system-directives
Jan 18, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0f286b6
Make invalid scope errors more useful
maartenvanvliet 8ef865d
Extract deprecated directive fields into separate phase
maartenvanvliet c1e108f
Add directive/1,2 to notation to apply type system directives
maartenvanvliet 2390500
Update lib/absinthe/schema/notation.ex
maartenvanvliet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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,58 @@ | ||
defmodule Absinthe.Phase.Schema.DeprecatedDirectiveFields do | ||
@moduledoc false | ||
# The spec of Oct 2015 has the onOperation, onFragment and onField | ||
# fields for directives (https://spec.graphql.org/October2015/#sec-Schema-Introspection) | ||
# See https://github.com/graphql/graphql-spec/pull/152 for the rationale. | ||
# These fields are deprecated and can be removed in the future. | ||
alias Absinthe.Blueprint | ||
|
||
use Absinthe.Schema.Notation | ||
|
||
@behaviour Absinthe.Phase | ||
|
||
def run(input, _options \\ []) do | ||
blueprint = Blueprint.prewalk(input, &handle_node/1) | ||
|
||
{:ok, blueprint} | ||
end | ||
|
||
defp handle_node(%Blueprint.Schema.ObjectTypeDefinition{identifier: :__directive} = node) do | ||
[types] = __MODULE__.__absinthe_blueprint__().schema_definitions | ||
|
||
new_node = Enum.find(types.type_definitions, &(&1.identifier == :deprecated_directive_fields)) | ||
|
||
fields = node.fields ++ new_node.fields | ||
|
||
%{node | fields: fields} | ||
end | ||
|
||
defp handle_node(node) do | ||
node | ||
end | ||
|
||
object :deprecated_directive_fields do | ||
field :on_operation, :boolean do | ||
deprecate "Check `locations` field for enum value OPERATION" | ||
|
||
resolve fn _, %{source: source} -> | ||
{:ok, Enum.any?(source.locations, &Enum.member?([:query, :mutation, :subscription], &1))} | ||
end | ||
end | ||
|
||
field :on_fragment, :boolean do | ||
deprecate "Check `locations` field for enum value FRAGMENT_SPREAD" | ||
|
||
resolve fn _, %{source: source} -> | ||
{:ok, Enum.member?(source.locations, :fragment_spread)} | ||
end | ||
end | ||
|
||
field :on_field, :boolean do | ||
deprecate "Check `locations` field for enum value FIELD" | ||
|
||
resolve fn _, %{source: source} -> | ||
{:ok, Enum.member?(source.locations, :field)} | ||
end | ||
end | ||
end | ||
end |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really happy with this, but can be removed when these fields are no longer necessary.