Comments (7)
Apologies, I misread the test. Let me dig into this later today.
from absinthe.
Hi @JonRowe can you show a concrete example?
from absinthe.
defmodule MagicValuesTest do
use ExUnit.Case, async: true
defmodule Schema do
use Absinthe.Schema
scalar :magic, open_ended: true do
parse(&{:ok, &1})
serialize(& &1)
end
object :something do
field :name, non_null(:string)
field :value, :magic
end
input_object :something_input do
field :name, non_null(:string)
field :value, :magic
end
query do
field :get_values, non_null(list_of(non_null(:something))) do
resolve(fn _, _, _ ->
{:ok, [%{name: "thing_one", value: ["magic"]}]}
end)
end
end
mutation do
field :patch_values, type: non_null(list_of(non_null(:something))) do
arg(:somethings, non_null(list_of(non_null(:something_input))))
resolve(fn _, %{somethings: somethings}, _ -> {:ok, somethings} end)
end
end
end
setup do
Absinthe.Test.prime(Schema)
end
test "query passes" do
assert {:ok, %{data: %{"getValues" => [%{"name" => "thing_one", "value" => ["magic"]}]}}} =
"""
query {
getValues {
name
value
}
}
"""
|> Absinthe.run(Schema, context: %{}, variables: %{})
end
test "mutation passes without a list" do
assert {:ok, %{data: %{"patchValues" => [%{"name" => "thing_one", "value" => _}]}}} =
"""
mutation patchValues($somethings: [SomethingInput!]!) {
patchValues(somethings: $somethings) {
name
value
}
}
"""
|> Absinthe.run(
Schema,
context: %{},
variables: %{
"somethings" => [
%{"name" => "thing_one", "value" => "magic"}
]
}
)
end
test "mutation fails" do
assert {:ok, %{data: %{"patchValues" => [%{"name" => "thing_one", "value" => ["magic"]}]}}} =
"""
mutation patchValues($somethings: [SomethingInput!]!) {
patchValues(somethings: $somethings) {
name
value
}
}
"""
|> Absinthe.run(
Schema,
context: %{},
variables: %{
"somethings" => [
%{"name" => "thing_one", "value" => ["magic"]}
]
}
)
end
end
from absinthe.
Hey Jon I think you're confused abut how open ended scalars are supposed to work. You've got your open ended scalar deep inside other structures. Those structures are not invalidated or consumed by the scalar just because they have an open ended scalar inside. If you want to have your open ended scalar consume the entire input you'd do something more like:
arg :somethings, :magic
I can try to find time later to edit your example to show what I mean. The reason you have versions that pass is that you are passing in JSON structures that are just straight up compatible with the values you have. It'd work even if you used :string
instead of :magic
.
from absinthe.
Those structures are not invalidated or consumed by the scalar just because they have an open ended scalar inside.
I know that, thats the point, I want name to be a mandatory string, and I only want value to be open ended, hence why I showed if I use another non list value it works, objects, strings, booleans all work in the fashion I expect its only the list that triggers the invalid argument
from absinthe.
the problem happens trying to use this scalar for mutations, one of the sub type data we need to send is a list
I'm facing the same requirements right now, and I was hoping that open-ended scalars would help here so I could avoid needing to have a JSON string scalar. Any advice if that could be accomplished?
from absinthe.
As a workaround you can use a structure like {entries: list}
as the scalar, its not great but it works
from absinthe.
Related Issues (20)
- False positive error for non_null validation HOT 2
- Using GraphQL (and perhaps Absinthe) in messages? HOT 3
- small CSS issue on the Absinthe landing page HOT 3
- add support for `config` functions (on subscriptions) in hydrate/2
- Resolving field of type `[[Value]!]!]` seems to fail with valid values HOT 2
- Compilation infinite loop leaking memory HOT 5
- Introspection query fails when using a prototype schema that defines types for use by directive arguments HOT 3
- Not having access to `conn` leads to degraded DX and performance HOT 1
- Absinthe.Subscription.unsubscribe doesn't work HOT 4
- Proposal - add a GRAPHQL sigil HOT 1
- Feature Request: customizable docset runner for Subscriptions HOT 1
- schema compilation goes into infinite recurion HOT 1
- Warning you must add "compilers: [:yecc] ++ Mix.compilers()" after updating to elixir 1.16
- Strings containing only whitespace are being trimmed to an empty string HOT 3
- Absinthe.Formatter.format/2 formats input: into one very long line HOT 1
- Schema compilation fails when defining a camel cased directive HOT 1
- Unable to name Absinthe object `:quote` when on Elixir 1.16 HOT 2
- Possible Bug in dataloader resolution helper when parent Id is null HOT 1
- `import_sdl` could not parse SDL HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from absinthe.