Skip to content
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

Fix parsing of node IDs with local middleware in modern schemas (v1.4) #96

Merged
merged 2 commits into from
Nov 22, 2017
Merged

Fix parsing of node IDs with local middleware in modern schemas (v1.4) #96

merged 2 commits into from
Nov 22, 2017

Conversation

avitex
Copy link
Contributor

@avitex avitex commented Nov 21, 2017

Fixes #95

@avitex
Copy link
Contributor Author

avitex commented Nov 21, 2017

In the process of refactoring the tests by pulling the supporting schema's into one (see below), I'm coming up with another error that I think I've narrowed down to my macro usage (not currently in this PR).

defmodule Absinthe.Relay.Node.ParseIDsTest.SupportingSchema do
  defmacro __using__(flavor) do
    quote do
      use Absinthe.Schema
      use Absinthe.Relay.Schema, unquote(flavor)
      # ...
    end
  end
end

defmodule Absinthe.Relay.Node.ParseIDsTest.SchemaClassic do
  use Absinthe.Relay.Node.ParseIDsTest.SupportingSchema, :classic
end

defmodule Absinthe.Relay.Node.ParseIDsTest.SchemaModern do
  use Absinthe.Relay.Node.ParseIDsTest.SupportingSchema, :modern
end

This test fails with Unknown argument \"input\" on field \"updateParentLocalMiddleware\" of type \"RootMutationType\".", and I have confirmed with Absinthe.Schema.types/1 that it is indeed the case.
Note manually pasting the schema body into SchemaClassic and SchemaModern works.

test "for modern schema" do
  encoded_parent_id = Base.encode64("Parent:1")
  encoded_child1_id = Base.encode64("Child:1")
  encoded_child2_id = Base.encode64("Child:1")
  result =
    """
    mutation FoobarLocal {
      updateParentLocalMiddleware(input: {
        parent: {
          id: "#{encoded_parent_id}",
          children: [{id: "#{encoded_child1_id}"}, {id: "#{encoded_child2_id}"}, {id: null}],
          child: {id: "#{encoded_child2_id}"}
        }
      }) {
        parent {
          id
          children { id }
          child { id }
        }
      }
    }
    """
    |> Absinthe.run(SchemaModern)

  expected_parent_data = %{
    "parent" => %{
      "id" => encoded_parent_id, # The output re-converts everything to global_ids.
      "children" => [%{"id" => encoded_child1_id}, %{"id" => encoded_child2_id}, nil],
      "child" => %{
        "id" => encoded_child2_id
      }
    }
  }
  assert {:ok, %{data: %{"updateParentLocalMiddleware" => expected_parent_data}}} == result
end

@avitex
Copy link
Contributor Author

avitex commented Nov 21, 2017

As this PR works with it's current test, shall I move this to a separate issue?

@bruce
Copy link
Contributor

bruce commented Nov 21, 2017

@avitex If it's for what you think is a different issue, then definitely pull it out. Let's keep these as narrow as possible.

@bruce bruce self-assigned this Nov 22, 2017
@bruce bruce merged commit ea68fb5 into absinthe-graphql:master Nov 22, 2017
@bruce bruce added the Type:Bug label Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants