Skip to content

Commit

Permalink
v1.3: Middleware, Logger, Included Custom Types, etc (#284)
Browse files Browse the repository at this point in the history
* Add logging, with support for filtering (#280)

* Support log: false configuration

* Address some feedback, clean up defaults (#282)

* Middleware (#254)

* minor optimization around arguments

* basic functionality

* almost green tests

* green tests

* handle middleware callbacks

* move plugins over to the middleware namespace

* forgot files as usual

* significant progress

* remove async and batch indirection

* rename Absinthe.Resolution.Middleware => Absinthe.Middleware

* handle before and after resolution

* some middleware testing

* improved resolution state names

* plug is now middleware

* finalize name for ensuring middleware

* doc updates

* it helps if you commit all the files

* finalizing names

* handle commentary

* better doc header

* Schema ensure query type (#226)

* Add query type rule

* Start to fix tests with querytype

* Add test

* fix more tests with query type

* Remove double imports

* Remove unused Type

* Add Explanation to FieldImportExist

* Fix the last two tests

Rewinding my own mistakes

* Fixed valid_schema

* ensure anon function form works

* context modification test

* more docs

* updated travis

* last doc tweak

* changelog update

* version bump

* correct version

* typo fix

* Date and Time Scalars (#256)

* added utc_datetime as a built-in scalar

* added naive datetime as a built-in scalar

* added date as a built-in scalar

* added time as a built-in scalar

* removed datetime types from built_ins

* moved datetime types to new extensions module

* added stricter pattern matching to datetime parser

* elixir 1.4 for travis

* fixed parsing and renamed module

* bumped elixir version

* bumped elixir version for travis

* testing against UTC offsets

* testing parsing 0-utc offset

* parsers are passed a blueprint input struct instead of a string

* added high-level tests for custom types

* build fix

* Use Markdown list syntax for nicer rendering (#285)

* changelog entry

* doc fix

* Support for `to_string/1` compatible error tuples in resolution  (#286)

* Use to_string for error messages

Sometimes you get other types in {:error, value}, like atom and integers,
and instead of people handling the converation themselves it's better just
returning the string equivalent of the atom inline with what json libraries
like Poison do or any other type that can be a string.

An example would be if you are doing `with` in you body you get the error
message from the library you are using. In guardian case you could get:
`{:error, :token_expired}`

* Changes for bruce

* Add changelog entry

* Moving TODOs to PR

* better changelog for beta

* fix bug where root query and mutation types had nil identifiers

* version bump

* provide test helping primer function

* docs

* Tuning (#292)

* do expansion prior so that we don't have to do it in resolution

* faster field applies check

* get rid of infinite loops and improved type condition handling

* add renamed file, and code reorganization

* so close to green

* tests are green at last

* remove bug line

* Fix #244

* Interface subtype (#293)

* Add failing test for interface subtype (#288)

This shows that an implementor of an interface with a more specific
field than expected will not compile.

* test fixes

* fixes to enable absinthe relay

* test prime bug fix

* more assertive

* resurrect plugin module as the before/after callbacks from middleware

* middleware.t => middleware.spec

* move scalar and enum serialization to the result phase (#296)

* remove commented out debug statements

* Add Absinthe.Pipeline.replace/3 (#300)

* Add Pipeline.replace/3

* Better type spec for Type.Directive

* Make Pipeline.replace/3 more flexible

* Clean up some warnings

* Prepare 1.3.0-beta.2

* Fix doc typo

* Another doc fix

* laxer test time for travis

* Batch resolution phase (#302)

* basic work on batching resolution phase

* bug fix

* remove warnings

* Changed HandleAuth to HandleError (#297)

* minor tweaks to support absinthe plug batching

* Extensions (#306)

* make the whole pipeline work with blueprints

* extensions test

* bug fixes

* version bump

* if a validation phase cannot jump, it returns an error instead of an ok tuple from the phase

* remove strange indentation

* fix performance issue, need to fix some tests though (#307)

* fix performance issue, need to fix some tests though

* green tests
  • Loading branch information
benwilson512 committed Apr 13, 2017
1 parent c575157 commit ffbec4d
Show file tree
Hide file tree
Showing 103 changed files with 2,704 additions and 899 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
@@ -1,10 +1,9 @@
language: elixir
elixir: 1.3.0
elixir: 1.4.2
notifications:
recipients:
- bruce.williams@cargosense.com
- ben.wilson@cargosense.com
otp_release:
- 18.0
- 19.0
- 19.2
script: "MIX_ENV=test mix local.hex --force && MIX_ENV=test mix do deps.get, test"
37 changes: 37 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,42 @@
# Changelog

## 1.3.0
### Status: Beta

- Added `Absinthe.Logger` -- adds configurable pipeline and variable logging
with filtering support (filters "token" and "password" by default). Used by
the `absinthe_plug` package.

- Enhancement: Added resolution middleware. See the `Absinthe.Middleware`
moduledocs.
- Enhancement: Middleware can be used to change the context. Use this
judiciously.
- Enhancement: Added built-in date and time types. Simply `import_types
Absinthe.Type.Custom` in your schema to use.
- Enhancement: Error tuple values can now be anything that's compatible with
`to_string/1`
- Enhancement: Substantial performance improvements for type conditions and
abstract type return values
- Enhancement: Added `Absinthe.Pipeline.replace/3` for easier modification of
pipeline phases.
- Enhancement: Scalar and Enum serialization moved to the
`Absinthe.Phase.Document.Result` phase, making customization of serialization
easier.

- Bug Fix: All interfaces an object claims to implement are checked at compile
time, instead of just the first.

- Breaking change: Plugins have been replaced by middleware, see the middleware
docs.
- Breaking change: `default_resolve` is no longer valid, see
`Absinthe.Middleware`.
- Breaking change: A root `query` object is now required, per the GraphQL spec.
- Breaking change: `Absinthe.Type.Interface.implements/2` is now `implements/3`
with the last argument being the schema.

- Cleanup: Undocumented module `InterfaceMap` removed as it was no longer being
used.

## v1.2.6

- Enhancement: Query complexity analysis!
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe.ex
Expand Up @@ -223,7 +223,7 @@ defmodule Absinthe do
def run(document, schema, options \\ []) do
pipeline = Absinthe.Pipeline.for_document(schema, options)
case Absinthe.Pipeline.run(document, pipeline) do
{:ok, result, _phases} ->
{:ok, %{result: result}, _phases} ->
{:ok, result}
{:error, msg, _phases} ->
{:error, msg}
Expand Down
15 changes: 13 additions & 2 deletions lib/absinthe/blueprint.ex
Expand Up @@ -14,25 +14,36 @@ defmodule Absinthe.Blueprint do
types: [],
directives: [],
fragments: [],
name: nil,
schema: nil,
adapter: nil,
# Added by phases
flags: %{},
errors: [],
resolution: %Blueprint.Document.Resolution{}
input: nil,
resolution: %Blueprint.Document.Resolution{},
result: %{},
]

@type t :: %__MODULE__{
operations: [Blueprint.Document.Operation.t],
types: [Blueprint.Schema.t],
directives: [Blueprint.Schema.DirectiveDefinition.t],
name: nil | String.t,
fragments: [Blueprint.Document.Fragment.Named.t],
schema: nil | Absinthe.Schema.t,
adapter: nil | Absinthe.Adapter.t,
# Added by phases
errors: [Absinthe.Phase.Error.t],
flags: flags_t,
resolution: Blueprint.Document.Resolution.t
resolution: Blueprint.Document.Resolution.t,
result: result_t,
}

@type result_t :: %{
optional(:data) => term,
optional(:errors) => [term],
optional(:extensions) => term,
}

@type node_t ::
Expand Down
8 changes: 5 additions & 3 deletions lib/absinthe/blueprint/document/resolution.ex
Expand Up @@ -8,13 +8,15 @@ defmodule Absinthe.Blueprint.Document.Resolution do
@type acc :: map

defstruct [
validation: [],
validation_errors: [],
result: nil,
acc: %{}
acc: %{},
context: %{},
root_value: %{},
]

@type t :: %__MODULE__ {
validation: [Phase.Error.t],
validation_errors: [Phase.Error.t],
result: nil | Resolution.Object.t,
acc: acc,
}
Expand Down
4 changes: 3 additions & 1 deletion lib/absinthe/blueprint/document/resolution/leaf.ex
Expand Up @@ -9,14 +9,16 @@ defmodule Absinthe.Blueprint.Document.Resolution.Leaf do
:emitter,
:value,
errors: [],
flags: %{}
flags: %{},
extensions: %{},
]

@type t :: %__MODULE__{
emitter: Blueprint.Document.Field.t,
value: Blueprint.Document.Resolution.node_t,
errors: [Phase.Error.t],
flags: Blueprint.flags_t,
extensions: %{any => any},
}

end
5 changes: 3 additions & 2 deletions lib/absinthe/blueprint/document/resolution/list.ex
Expand Up @@ -8,16 +8,17 @@ defmodule Absinthe.Blueprint.Document.Resolution.List do
defstruct [
:emitter,
:values,
# Added by phases
errors: [],
flags: %{}
flags: %{},
extensions: %{},
]

@type t :: %__MODULE__{
emitter: Blueprint.Document.Field.t,
values: [Blueprint.Document.Resolution.node_t],
errors: [Phase.Error.t],
flags: Blueprint.flags_t,
extensions: %{any => any},
}

end
7 changes: 4 additions & 3 deletions lib/absinthe/blueprint/document/resolution/object.ex
Expand Up @@ -9,16 +9,17 @@ defmodule Absinthe.Blueprint.Document.Resolution.Object do
:root_value,
:emitter,
:fields,
# Added by phases
errors: [],
flags: %{}
flags: %{},
extensions: %{},
]

@type t :: %__MODULE__{
emitter: Blueprint.Document.Field.t,
fields: [Blueprint.Document.Resolution.node_t],
errors: [Phase.Error.t],
flags: Blueprint.flags_t
flags: Blueprint.flags_t,
extensions: %{any => any},
}

end
29 changes: 0 additions & 29 deletions lib/absinthe/blueprint/document/resolution/plugin_invocation.ex

This file was deleted.

1 change: 1 addition & 0 deletions lib/absinthe/blueprint/type_reference/name.ex
Expand Up @@ -7,6 +7,7 @@ defmodule Absinthe.Blueprint.TypeReference.Name do
@enforce_keys [:name]
defstruct [
:name,
:schema_node,
errors: []
]

Expand Down
12 changes: 6 additions & 6 deletions lib/absinthe/introspection/field.ex
Expand Up @@ -12,7 +12,7 @@ defmodule Absinthe.Introspection.Field do
name: "__typename",
type: :string,
description: "The name of the object type currently being queried.",
resolve: fn
middleware: [Absinthe.Resolution.resolver_spec(fn
_, %{parent_type: %Type.Object{} = type} ->
{:ok, type.name}
_, %{source: source, parent_type: %Type.Interface{} = iface} = env ->
Expand All @@ -29,7 +29,7 @@ defmodule Absinthe.Introspection.Field do
type ->
{:ok, type.name}
end
end
end)]
}
end

Expand All @@ -48,10 +48,10 @@ defmodule Absinthe.Introspection.Field do
}
}
},
resolve: fn
middleware: [Absinthe.Resolution.resolver_spec(fn
%{name: name}, %{schema: schema} ->
{:ok, Schema.lookup_type(schema, name)}
end
end)]
}
end

Expand All @@ -60,10 +60,10 @@ defmodule Absinthe.Introspection.Field do
name: "__schema",
type: :__schema,
description: "Represents the schema",
resolve: fn
middleware: [Absinthe.Resolution.resolver_spec(fn
_, %{schema: schema} ->
{:ok, schema}
end
end)]
}
end

Expand Down
4 changes: 2 additions & 2 deletions lib/absinthe/language/document.ex
Expand Up @@ -64,8 +64,8 @@ defmodule Absinthe.Language.Document do
Language.Fragment,
]

def convert(node, _) do
Enum.reduce(node.definitions, %Blueprint{}, &convert_definition(&1, node, &2))
def convert(node, bp) do
Enum.reduce(node.definitions, bp, &convert_definition(&1, node, &2))
end

defp convert_definition(%struct{} = node, doc, blueprint) when struct in @operations do
Expand Down

0 comments on commit ffbec4d

Please sign in to comment.