tendant / graphql-clj

A Clojure library that provides GraphQL implementation.
Eclipse Public License 1.0
285 stars 22 forks source link

Nested input object does not work #48

Closed bjonica closed 7 years ago

bjonica commented 7 years ago

Whenever a schema has an input object within another input object, I get a "Expected 'SomeType', found not an object." error. Not sure what's going on.

Given schema:

schema {
  query: Query
}

input TextInput {
  value: String
}

input WorldInput {
  text: TextInput
}

type Query {
  hello(world: WorldInput): String
}

and query:

{
  hello(world: {text: "World"})
}

The response from the server is

  "errors": [
    {
      "error": "Argument 'world' of type 'WorldInput' has invalid value: {text: World}. Reason: Expected 'WorldInput', found not an object.",
      "loc": {
        "line": 2,
        "column": 16
      }
    }
  ]
}
xsc commented 7 years ago

world is a TextInput in your example, not a String, so the correct query should be (but I haven't run it):

{
  hello(world: {text: {value: "World"}})
}

So, the query is indeed invalid but the error message is a bit misleading. (Or the schema/query you supplied is not the one that produced the error?)

bjonica commented 7 years ago

My mistake. Corrected the query to yours, but same problem.

{
  "errors": [
    {
      "error": "Argument 'world' of type 'WorldInput' has invalid value: {text: [:object-value {:value World}]}. Reason: Expected 'WorldInput', found not an object.",
      "loc": {
        "line": 2,
        "column": 16
      }
    }
  ]
}
tendant commented 7 years ago

I am not sure whether nested input type are supposed to work or not.

Input Type is defined in GraphQL Spec:

GraphQL describes the types of data expected by query variables. Input types may be lists of another input type, or a non‐null variant of any other input type.

Variables can only be scalars, enums, input objects, or lists and non‐null variants of those types. These are known as input types. Objects, unions, and interfaces cannot be used as inputs.

tendant commented 7 years ago

Just found this from type system definition:

An Input Object defines a set of input fields; the input fields are either scalars, enums, or other input objects. This allows arguments to accept arbitrarily complex structs.

Nested input type should be supported.

tendant commented 7 years ago

Currently parser treats input values as object values which is incorrect.

We need enhance the parser and validator to support this case.

tendant commented 7 years ago

This issue is fixed in latest version.