Giter Site home page Giter Site logo

Comments (7)

benwilson512 avatar benwilson512 commented on May 27, 2024 1

Apologies, I misread the test. Let me dig into this later today.

from absinthe.

benwilson512 avatar benwilson512 commented on May 27, 2024

Hi @JonRowe can you show a concrete example?

from absinthe.

JonRowe avatar JonRowe commented on May 27, 2024
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.

benwilson512 avatar benwilson512 commented on May 27, 2024

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.

JonRowe avatar JonRowe commented on May 27, 2024

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.

Wigny avatar Wigny commented on May 27, 2024

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.

JonRowe avatar JonRowe commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.