'GraphQl mutation error as "Cannot read property '_id' of undefined"

I want to create a mutation. So my code snipped like that:

Mutation: {
        createSocial: async (_, { social }) => {

            console.log(social) ===========================================>>>>>>> undefined

            const db = await mongo.then(d => d.db('social'))
            const { insertedId } = await db.collection('social-medias').insertOne(social)
            return insertedId.toString()
        }
    }

And my query like that:

module.exports = gql`
    extend type Query {
        social(id: String!): SocialMedia
    }
    extend type Mutation{
        createSocial(social: SocialMediaInput) : Boolean
    }
`

finally my type like that:

input FacebookProviderInput{
    user_id: String
    access_token: String
}
type FacebookProvider {
    user_id: String!
    access_token: String!
}
input SocialMediaProviderInput{
    facebook: FacebookProviderInput
}
type SocialMediaProvider {
    facebook: FacebookProvider
}
input SocialMediaInput{
    provider: SocialMediaProviderInput
}
type SocialMedia {
    merchant_id: String!
    provider: SocialMediaProvider
}

With this code snippeds I send a request as:

enter image description here

But I getting error as you see. Why Im getting this error? How can solve this error. Please Help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source