Search code examples
expressgraphqlapollo-client

GraphQL - Parameters not being passed to backend in mutation


I've just started with GraphQL and mutations and am having this issue.

When I attempt to pass data to my GraphQL server, it seems the args parameter does not register the args that I am attempting to pass.

When I console.log them, they appear as undefined, but the method is working and receiving the request.

Does anything seem incorrect below? I'm just getting my head around it so would appreciate any feedback.

This is the query I'm attempting to run from GraphiQL

mutation {
  addDelivery(
    carrier: "AusPost", 
    goodsDelivered:[],
    receiver: {
      first_name:"ll",
      last_name:"test",
      receiver_email: "[email protected]"
    },
    consignmentNumber:"AAAA000",
    poNumber:"PO0000"
  ) {
    id
    carrier {
      iD
      carrier_name
    }
  }
}

My schema:

type ReceiverType{
    first_name: String
    last_name: String
    receiver_email: String
}

type ItemType {
    item_type: String,
    quantity: String
}

type Deliveries {
    carrier: Carrier
    consignmentNumber: String
    goodsDelivered: [String]
    id: ID
    items: [ItemType]
    poNumber: String
    receiver: ReceiverType
}

type Carrier{
    iD: ID
    carrier_name: String
}

input Item {
    item_type: String,
    quantity: String
}

type Query {
    deliveries: [Deliveries]
}

input Receiver {
    first_name: String
    last_name: String
    receiver_email: String
}

type Mutation {
    addDelivery(
        carrier: String!,
        consignmentNumber: String!,
        goodsDelivered: [Item]!,
        poNumber: String!,
        receiver: [Receiver]! 
    ) : Deliveries
}

My add delivery resolver

addDelivery: async (parent, args, context, info) => {
    const delivery = new Deliveries({
        receiver: {
            first_name: args.first_name,
            last_name: args.last_name,
            receiver_email: args.receiver_email
        },
        items: args.items,
        consignment_no: args.consignment_no,
        po_number: args.po_number,
        carrier_id: args.carrier_id,
        delivery_id: args.delivery_id
    });

    await delivery.save();
    return delivery;
}

Solution

  • I changed the signature to the following and it resolved the issue.

    addDelivery: async ({receiver, items, consignment_no, po_number, carrier_id, delivery_id}) => {