absinthe-graphql / absinthe

The GraphQL toolkit for Elixir
http://absinthe-graphql.org
Other
4.29k stars 526 forks source link

Absinthe.run/3 operation_name not allowing null in non current operations #682

Closed d-webs closed 5 years ago

d-webs commented 5 years ago

If submitting a bug, please provide the following:

Environment

Expected behavior

Based on the documentation for Absinthe.run/3, I would expect to be able to pass the following document:

mutation Create($createResource: CreateResourceInput!) {
    create(resource: $createResource) { name, id }
}

mutation Update($updateResource: UpdateResourceInput!) {
    create(resource: $updateResource) { name, id }
}

and run Absinthe.run(document, MyApp.Schema, variables: %{...}, operation_name: "Create"), which would in turn only execute the first mutation in the document.

Actual behavior

Instead, all mutations run regardless of which operation_name I provide, and I get errors for missing fields, etc., for mutations that I did not intend to run. I have done the following to troubleshoot:

Below is the error I get when I attempt to run a test against a single mutation in the document:

code:  assert {:ok, %{data: data}} = result
right: {:ok,
%{
  errors: [
    %{
      locations: [%{column: 0, line: 42}],
      message: "In argument \"modifier_choice\": Expected type \"DeleteModifierChoiceInput!\", found null."
    },
    %{
      locations: [%{column: 0, line: 41}],
      message: "Variable \"modifier_choice\": Expected non-null, found null."
    },
    %{
      locations: [%{column: 0, line: 37}],
      message: "In argument \"modifier_choice\": Expected type \"UpdateModifierChoiceInput!\", found null."
    },
    %{
      locations: [%{column: 0, line: 36}],
      message: "Variable \"modifier_choice\": Expected non-null, found null."
    },
    %{
      locations: [%{column: 0, line: 32}],
      message: "In argument \"modifier_choice\": Expected type \"CreateModifierChoiceInput!\", found null."
    },
    %{
      locations: [%{column: 0, line: 31}],
      message: "Variable \"modifier_choice\": Expected non-null, found null."
    },
    %{
      locations: [%{column: 0, line: 27}],
      message: "In argument \"modifier_group\": Expected type \"DeleteModifierGroupInput!\", found null."
    },
    %{
      locations: [%{column: 0, line: 26}],
      message: "Variable \"modifier_group\": Expected non-null, found null."
    },
    %{
      locations: [%{column: 0, line: 22}],
      message: "In argument \"modifier_group\": Expected type \"UpdateModifierGroupInput!\", found null."
    },
    %{
      locations: [%{column: 0, line: 21}],
      message: "Variable \"modifier_group\": Expected non-null, found null."
    },
    %{
      locations: [%{column: 0, line: 17}],
      message: "In argument \"modifier_group\": Expected type \"CreateModifierGroupInput!\", found null."
    },
    %{
      locations: [%{column: 0, line: 16}],
      message: "Variable \"modifier_group\": Expected non-null, found null."
    },
    %{
      locations: [%{column: 0, line: 12}],
      message: "Argument \"product\" has invalid value $product.\nIn field \"description\": Unknown field."
    },
    %{
      locations: [%{column: 0, line: 2}],
      message: "Argument \"product\" has invalid value $product.\nIn field \"name\": Expected type \"String!\", found null.\nIn field \"category\": Expected type \"String!\", found null.\nIn field \"catalogId\": Expected type \"ID!\", found null.\nIn field \"basePrice\": Expected type \"CurrencyInput!\", found null.\nIn field \"id\": Unknown field."
    }
  ]
}}

It appears all the mutations that I did not intend to run are throwing errors, as I have not provide valid variables to them.

Relevant Schema/Middleware Code

benwilson512 commented 5 years ago

This is actually unrelated to mutations and more about variables. The variables of queries or mutations that are not current are still being checked for null. Fixed in the PR.