Answer the question
In order to leave comments, you need to log in
Change graphQL mutation code?
I'm just studying this bundle and ran into some misunderstandings?
import {
GraphQLNonNull,
GraphQLID,
GraphQLString
} from 'graphql';
import { clubType } from '../../types/club';
import ClubModel from '../../../models/club';
export default {
type: clubType,
args: {
id: {
name: 'id',
type: new GraphQLNonNull(GraphQLID)
},
name: {
type: new GraphQLNonNull(GraphQLString)
},
position: {
type: new GraphQLNonNull(GraphQLString)
},
league: {
type: new GraphQLNonNull(GraphQLString)
}
},
resolve(root, params) {
const updateClub = ClubModel.findByIdAndUpdate(params.id, {
$set: {
name: params.name,
position: params.position,
league: params.league
}
}, {
new: true
})
if (!updateClub) {
throw new Error('error update club')
}
return updateClub;
}
}
mutation {
UpdateClub(id: "5b447f4d0f2f3b03e20001e4", name: "Zenit FC", position: "1", league : "Rus") {
_id
name
position
league
createdAp
updateAt
}
}
position
, I would transfer only this data?mutation {
UpdateClub(id: "5b447f4d0f2f3b03e20001e4", position: "1") {
_id
name
position
league
createdAp
updateAt
}
}
Answer the question
In order to leave comments, you need to log in
Use the Relay approach to solve this problem, instead of describing all the arguments in a mutation, just make an input and pass the desired data into it. Here is a good article to read.
input UpdateClubInput {
id: ID!
name: String
position: String
league: String
}
mutation {
UpdateClub(input: UpdateClubInput!): Club
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question