Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 18 mongoose graphql error #26

Open
Human-bio opened this issue May 27, 2021 · 2 comments
Open

Lesson 18 mongoose graphql error #26

Human-bio opened this issue May 27, 2021 · 2 comments

Comments

@Human-bio
Copy link

Human-bio commented May 27, 2021

I clonned the repo attached my mongo database but this error showed up when I requested a mutation"message": "(Unauthorized) not authorized on admin to execute command { insert: "authors",
mongoose schema code

const graphql = require('graphql');
const Book = require('../models/book');
const Author = require('../models/Author');
const _ = require('lodash');

const {
    GraphQLObjectType,
    GraphQLString,
    GraphQLSchema,
    GraphQLID,
    GraphQLInt,
    GraphQLList
} = graphql;

const BookType = new GraphQLObjectType({
    name: 'Book',
    fields: ( ) => ({
        id: { type: GraphQLID },
        name: { type: GraphQLString },
        genre: { type: GraphQLString },
        author: {
            type: AuthorType,
            resolve(parent, args){
                //return _.find(authors, { id: parent.authorId });
            }
        }
    })
});

const AuthorType = new GraphQLObjectType({
    name: 'Author',
    fields: ( ) => ({
        id: { type: GraphQLID },
        name: { type: GraphQLString },
        age: { type: GraphQLInt },
        books: {
            type: new GraphQLList(BookType),
            resolve(parent, args){
                //return _.filter(books, { authorId: parent.id });
            }
        }
    })
});

const RootQuery = new GraphQLObjectType({
    name: 'RootQueryType',
    fields: {
        book: {
            type: BookType,
            args: { id: { type: GraphQLID } },
            resolve(parent, args){
                //return _.find(books, { id: args.id });
            }
        },
        author: {
            type: AuthorType,
            args: { id: { type: GraphQLID } },
            resolve(parent, args){
                //return _.find(authors, { id: args.id });
            }
        },
        books: {
            type: new GraphQLList(BookType),
            resolve(parent, args){
                //return books;
            }
        },
        authors: {
            type: new GraphQLList(AuthorType),
            resolve(parent, args){
                //return authors;
            }
        }
    }
});

const Mutation = new GraphQLObjectType({
    name: 'Mutation',
    fields: {
        addAuthor: {
            type: AuthorType,
            args: {
                name: { type: GraphQLString },
                age: { type: GraphQLInt }
            },
            resolve(parent, args){
                let author = new Author({
                    name: args.name,
                    age: args.age
                });
                return author.save();
            }
        }
    }
});

module.exports = new GraphQLSchema({
    query: RootQuery,
    mutation: Mutation
});
`
```
@Human-bio
Copy link
Author

node:31482) MongoError: (Unauthorized) not authorized on admin to execute command { insert: "authors", documents: [[{name gyfdgyiszukjfheusdzyih} {age 88} {_id ObjectID("60af9c682215ea7afad86f4c")} {__v 0}]], ordered: false, writeConcern: { w: "majority" }, txnNumber: 4.000000, $clusterTime: { clusterTime: {1622121571 1}, signature: { hash: {0 [134 224 34 24 72 83 84 21 31 152 195 189 83 14 136 196 101 10 239 180]}, keyId: 6954772510130831360.000000 } }, lsid: { id: {4 [115 137 219 18 191 230 79 106 130 121 29 168 108 239 195 227]} } }

@jessewriter
Copy link

i think the dependencies of this project are so out of date that a lot of things are not working as expected. needs a refresh using MongoDb and modern react functional components. wondering if anyone has refactored this yet as I feel like I have to start from scratch at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants