Hi,
This is my graphql schema, query and mutations.
I marked required fields in my schema with "!"
How I can create mutation to add new client?
Do I really need to write the same required fields again?
Like createClient(contactMethod: String!, hearAbout: String! ......... ): Client
import { MongoClients } from '/imports/api/collections.js';
const typeShard = `
type ClientProfile {
name: String!
surname: String!
address: String
language: String!
englishSpeaker: String
nationality: String
}
type ClientContactPerson {
email: [ClientEmail]
phone: [ClientPhone]
profile: ClientProfile
}
type ClientEmail {
address: String
}
type ClientPhone {
number: String
}
type Client {
_id: String
isEdit: Boolean
createdAt: String
shortId: Int
emails: [ClientEmail]
phone: [ClientPhone]
contactPerson: [ClientContactPerson]
profile: ClientProfile
comments: String
contactMethod: String!
hearAbout: String!
leadAgentId: String
branchId: String!
subscriber: Boolean
removed: Boolean
}
`;
const queryShard = `
getClient(shortId : Int!): Client
getAllClients: [Client]
`;
const mutationShard = `
removeClient(shortId : Int!): Client
createClient(contactMethod: String!, hearAbout: String! ......... ): Client
`;
const resolvers = {
Query: {
getClient(root, { shortId }) {
return MongoClients.findOne({ shortId });
},
getAllClients: () => MongoClients.find().fetch(),
},
Mutation: {
removeClient(root, { shortId }) {
const client = MongoClients.findOne({ shortId });
if (!client) throw new Error(`Couldn't find client with id ${shortId}`);
MongoClients.remove({ shortId });
return client;
},
createClient: (_, args) => {
const data = Object.assign({}, { createdAt: new Date() }, args);
const clientId = MongoClients.insert(data);
return MongoClients.findOne(clientId);
},
},
};
export { typeShard, queryShard, mutationShard, resolvers };