Skip to content

Commit

Permalink
Inline meta tag fix (#24)
Browse files Browse the repository at this point in the history
* Update packages

* Autoformat

* Add tests for inline syntax, update readme for correct syntax.

Fixes #23
  • Loading branch information
Andrew Thal authored Jan 14, 2019
1 parent b126311 commit 046f316
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 75 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end

# or

object :user, meta: [max_age: 30] do
object :user, meta: [cache: [max_age: 30]] do
# ...
end
```
Expand Down
16 changes: 10 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
%{
"absinthe": {:hex, :absinthe, "1.4.7", "c92411307e01d0193f2eafc0d6e28273e476f66d5d20e031f879ce1fec0ad9e3", [:mix], [{:dataloader, "~> 1.0.0", [hex: :dataloader, repo: "hexpm", optional: true]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"absinthe_plug": {:hex, :absinthe_plug, "1.4.2", "01bf16f0a637869bcc0a1919935f08ff853501004e7549ddaa3a7788deb48965", [:mix], [{:absinthe, "~> 1.4", [hex: :absinthe, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.2 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.2", "993e0a95e9fbb790ac54ea58e700b45b299bd48bc44b4ae0404f28161f37a83e", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"mime": {:hex, :mime, "1.2.0", "78adaa84832b3680de06f88f0997e3ead3b451a440d183d688085be2d709b534", [:mix], [], "hexpm"},
"plug": {:hex, :plug, "1.4.4", "279b547662272cd835a8ca089717201dd3be51bb4705354eaf1b0346744acc82", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
"absinthe": {:hex, :absinthe, "1.4.13", "81eb2ff41f1b62cd6e992955f62c22c042d1079b7936c27f5f7c2c806b8fc436", [:mix], [{:dataloader, "~> 1.0.0", [hex: :dataloader, repo: "hexpm", optional: true]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"absinthe_plug": {:hex, :absinthe_plug, "1.4.6", "ac5d2d3d02acf52fda0f151b294017ab06e2ed1c6c15334e06aac82c94e36e08", [:mix], [{:absinthe, "~> 1.4.11", [hex: :absinthe, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.2 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.19.2", "6f4081ccd9ed081b6dc0bd5af97a41e87f5554de469e7d76025fba535180565f", [:mix], [{:earmark, "~> 1.2", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
"plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"},
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
}
201 changes: 133 additions & 68 deletions test/apollo_tracing_test.exs
Original file line number Diff line number Diff line change
@@ -1,97 +1,162 @@
defmodule ApolloTracingTest do
use ExUnit.Case
doctest ApolloTracing
defmodule SharedTestCase do
defmacro define_tests(do: block) do
quote do
defmacro __using__(options) do
block = unquote(Macro.escape(block))

quote do
use ExUnit.Case

@moduletag unquote(options)
unquote(block)
end
end
end
end
end

defmodule ApolloTracingSharedTests do
import SharedTestCase

define_tests do
@query """
query {
getPerson {
name
age
cars { make model }
}
}
"""

def get_result(schema, query) do
pipeline = ApolloTracing.Pipeline.default(schema, [])

query
|> Absinthe.Pipeline.run(pipeline)
|> case do
{:ok, %{result: result}, _} -> result
error -> error
end
end

test "should have :tracing in extension", %{schema: schema} do
result = get_result(schema, @query)
assert result.extensions.tracing
end

test "should have start and end times in tracing", %{schema: schema} do
result = get_result(schema, @query)
assert result.extensions.tracing.startTime
assert result.extensions.tracing.endTime
assert result.extensions.tracing.duration
end

test "should have 6 resolvers", %{schema: schema} do
result = get_result(schema, @query)
assert length(result.extensions.tracing.execution.resolvers) == 6
end

test "each resolver should have path, start_offset and duration", %{schema: schema} do
result = get_result(schema, @query)

for resolver <- result.extensions.tracing.execution.resolvers do
assert resolver.path
assert resolver.startOffset
assert resolver.duration
end
end

test "includes cache hints", %{schema: schema} do
result = get_result(schema, @query)
assert result.extensions.cacheControl.version == 1

assert result.extensions.cacheControl.hints == [
%{
path: ["getPerson"],
maxAge: 30,
scope: "PRIVATE"
},
%{
path: ["getPerson", "cars"],
maxAge: 600,
scope: "PUBLIC"
}
]
end
end
end

defmodule ApolloTracingTest do
defmodule TestSchema do
use Absinthe.Schema
use ApolloTracing

object :person do
meta(:cache, max_age: 30, scope: :private)

field :name, :string
field :age, non_null(:integer)
field :cars, list_of(:car)
field(:name, :string)
field(:age, non_null(:integer))
field(:cars, list_of(:car))
end

object :car do
meta(:cache, max_age: 600)

field :make, non_null(:string)
field :model, non_null(:string)
field(:make, non_null(:string))
field(:model, non_null(:string))
end

query do
field :get_person, list_of(non_null(:person)) do
resolve fn _, _ ->
{:ok, [
%{
name: "sikan", age: 20,
cars: [%{make: "Honda", model: "Accord"}]
}
]}
end
resolve(fn _, _ ->
{:ok,
[
%{
name: "sikan",
age: 20,
cars: [%{make: "Honda", model: "Accord"}]
}
]}
end)
end
end
end

setup_all do
pipeline = ApolloTracing.Pipeline.default(TestSchema, [])

result =
"""
query {
getPerson {
name
age
cars { make model }
}
}
"""
|> Absinthe.Pipeline.run(pipeline)
|> case do
{:ok, %{result: result}, _} -> result
error -> error
end

{:ok, %{result: result}}
end
use ApolloTracingSharedTests, schema: TestSchema
end

test "should have :tracing in extension", %{result: result} do
assert result.extensions.tracing
end
defmodule ApolloTracingInlineTest do
defmodule TestSchema do
use Absinthe.Schema
use ApolloTracing

test "should have start and end times in tracing", %{result: result} do
assert result.extensions.tracing.startTime
assert result.extensions.tracing.endTime
assert result.extensions.tracing.duration
end
object :person, meta: [cache: [max_age: 30, scope: :private]] do
field(:name, :string)
field(:age, non_null(:integer))
field(:cars, list_of(:car))
end

test "should have 6 resolvers", %{result: result} do
assert (length result.extensions.tracing.execution.resolvers) == 6
end
object :car, meta: [cache: [max_age: 600]] do
field(:make, non_null(:string))
field(:model, non_null(:string))
end

test "each resolver should have path, start_offset and duration", %{result: result} do
for resolver <- result.extensions.tracing.execution.resolvers do
assert resolver.path
assert resolver.startOffset
assert resolver.duration
query do
field :get_person, list_of(non_null(:person)) do
resolve(fn _, _ ->
{:ok,
[
%{
name: "sikan",
age: 20,
cars: [%{make: "Honda", model: "Accord"}]
}
]}
end)
end
end
end

test "includes cache hints", %{result: result} do
assert result.extensions.cacheControl.version == 1
assert result.extensions.cacheControl.hints == [
%{
"path": ["getPerson"],
"maxAge": 30,
"scope": "PRIVATE",
},
%{
"path": ["getPerson", "cars"],
"maxAge": 600,
"scope": "PUBLIC",
},
]
end
use ApolloTracingSharedTests, schema: TestSchema
end

0 comments on commit 046f316

Please sign in to comment.