1

Hello guys I got stuck in a mutation with array inside it to mutate multiple objects at a time.

So here is my Schema of my InstalmentsGroup

import mongoose from "mongoose";

const Schema = mongoose.Schema;

const InstalmentsGroupSchema = new Schema(
  {
    offer: {
      type: Schema.Types.ObjectId,
      ref: "Offer"
    },
    instalmentCount: { type: Number },
    instalmentAmout: { type: Number },
    dueTo: { type: Date }
  },
  { timestamps: true }
);

export default mongoose.model("InstalmentsGroup", InstalmentsGroupSchema);

These are my types

type Instalment {
    _id: ID!
    instalmentCount: Int!
    instalmentAmout: Int!
    dueTo: Date!
    instalmentGroup: InstalmentGroup
  }

  type InstalmentGroup {
    _id: ID!
    offer: ID!
    instalments: [Instalment!]!
  }

And this is my mutation

createInstalmentGroup(
  offer: ID!
  instalments: [Instalment!]!
): InstalmentGroup

And resolver

createInstalmentGroup: async (_, { ...args }, { user }) => {
    try {
      await requireAuth(user);
      const instalments = await InstalmentsGroup.create({ ...args });

      return instalments;
    } catch (error) {
      throw error;
    }
  }

Now all I got is this `Error: The type of Mutation.createInstalmentGroup(instalments:) must be Input Type but got: [Instalment!]!.`

What I want to do is something to look like this

mutation {
    createInstalmentGroup(
        offer: "5cc8876242b1ad68efdd7df3",
        instalments: [
            {
                instalmentCount: 1,
                instalmentAmout: 2000,
                dueTo: "2019-06-01T23:00:00.000Z"
            }. {
                instalmentCount: 2,
                instalmentAmout: 2000,
                dueTo: "2019-07-01T23:00:00.000~"
            }
        ]
    ) 
}
Markus Hayner
  • 2,869
  • 2
  • 28
  • 60
  • 1
    Duplicate of [GraphQL Error field type must be Input Type but got:](https://stackoverflow.com/questions/45806368/graphql-error-field-type-must-be-input-type-but-got) – Daniel Rearden May 03 '19 at 10:08
  • 1
    As noted in the accepted answer for the above, you need to add a separate input type in your schema that can be used inside arguments. An output type like `Instalment` cannot be used where an input type is expected. – Daniel Rearden May 03 '19 at 10:10
  • @DanielRearden thanks I made it working now all the best – Markus Hayner May 03 '19 at 10:34
  • Great. Feel free to upvote the accepted answer on the other question! – Daniel Rearden May 03 '19 at 10:35

0 Answers0