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