feat(server): prevent mutations with null values

This commit is contained in:
Joshua Seigler 2020-01-29 01:15:58 -05:00
parent 420a4739eb
commit dcb2421890

View file

@ -1,12 +1,12 @@
const {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLID,
GraphQLInt,
GraphQLList,
GraphQLSchema
GraphQLNonNull
} = require('graphql');
const _ = require('lodash');
const Book = require('../models/book');
const Author = require('../models/author');
@ -79,8 +79,8 @@ const Mutation = new GraphQLObjectType({
addAuthor: {
type: AuthorType,
args: {
name: { type: GraphQLString },
age: { type: GraphQLInt }
name: { type: new GraphQLNonNull(GraphQLString) },
age: { type: new GraphQLNonNull(GraphQLInt) }
},
resolve (parent, { name, age }) {
const author = new Author({
@ -93,9 +93,9 @@ const Mutation = new GraphQLObjectType({
addBook: {
type: BookType,
args: {
name: { type: GraphQLString },
genre: { type: GraphQLString },
authorId: { type: GraphQLID }
name: { type: new GraphQLNonNull(GraphQLString) },
genre: { type: new GraphQLNonNull(GraphQLString) },
authorId: { type: new GraphQLNonNull(GraphQLID) }
},
resolve (parent, { name, genre, authorId }) {
const book = new Book({