4

I have this schema:

type Preference{
    _id: ID!
    uID: ID!
    preferences: [Category!]!
}

type Category{
    name: String!
    subcategories: [String]!
}

type RootMutation{
    createPreference(perferenceInput: PerferenceInput) : Preference
}

input PerferenceInput{
    uID: String!
    preferences: [Category!]!
}

schema {    
    query: RootQuery
    mutation: RootMutation
}

type RootQuery {
    preferences: [Preference!]!
    category: [Category!]!
}

But Graphql gives me an error that states: message": "The type of PerferenceInput.preferences must be Input Type but got: [Category].", which I have traced back to be related to graphql not being able to parse the [Category] array.

I need to have this array as a nested array inside the Preference object, but somehow graphql is not able to parse this.. so, how can I pass the Category array to as an input type ?

Lasse
  • 597
  • 2
  • 10
  • 33
  • 1
    This question gets asked a lot. You can't use an object type where an input object type is expected (i.e. as an argument). A more detailed explanation can be found [here](https://stackoverflow.com/a/52745448/6024220). – Daniel Rearden Feb 15 '19 at 15:26

1 Answers1

4

This is well-known GraphQL limitation.

You can't use regular GraphQLObjectTypes as the type for an GraphQLInputObjectType field – you must use another GraphQLInputObjectType.

You can't mix input and output types in your schema. Input and output types have different type scope.

galkin
  • 5,264
  • 3
  • 34
  • 51