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

Different Folder structure but added mutations #4

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
"development": {
"username": "root",
"password": null,
"database": "sequelize-example",
"database": "graphql_example",
"host": "127.0.0.1",
"dialect": "mysql"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"database": "graphql_example",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"database": "graphql_example",
"host": "127.0.0.1",
"dialect": "mysql"
}
Expand Down
63 changes: 63 additions & 0 deletions graphql/mutations/Front_End_Calls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// READ ME !!!!
// ********************** FRONT END MUTATION CALLS ************************

// the id's would be querried on the front end componenet
// the hardcoded strings would be created from front end inputs
// so dont panic and make sure to change them to see results
// in the database


// ============ QUOTE MUTATIONS =========
// =============================
// creating a quote/adding it to author by author id
mutation {
addQuoteToAuthor(id: 3, quote: "adding this quote") {
id
}
}
// =============================
// destroying quote by quote id
mutation {
destroyQuoteFromAuthor(id: 14) {
author {
name
}
}
}
// =============================
// updating quote by quote id
mutation {
updateQuote (id: 4, quote: "this is that new new") {
id
}
}


// ============ AUTHOR MUTATIONS ============
// =============================
// creating an author
mutation {
createAuthor (
name: "Dirtbag",
last_name: "Steve"
) {
id
}
}
// =============================
// updating an author based on id
mutation {
updateAuthor (
id: 2,
name: "new",
last_name: "newer") {
id
}
}
// =============================
// destroys author from db by id
mutation {
destroyAuthor(id: 2) {
id
}
}
21 changes: 21 additions & 0 deletions graphql/mutations/author/createAuthor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
GraphQLString,
GraphQLNonNull,
GraphQLInputObjectType
} from 'graphql';

import models from '../../../models/index.js';
import Author from '../../types/author.js';

//working
export default {
type: Author,
name: 'createAuthor',
args: {
name: { type: GraphQLString },
last_name: { type: GraphQLString }
},
resolve(root, args) {
return models.author.create({name: args.name,last_name: args.last_name});
}
};
21 changes: 21 additions & 0 deletions graphql/mutations/author/destroyAuthor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
GraphQLID,
GraphQLString,
GraphQLNonNull,
GraphQLInputObjectType
} from 'graphql';

import models from '../../../models/index.js';
import Author from '../../types/author.js';

//working
export default {
type: Author,
name: 'destroyAuthor',
args: {
id: { type: GraphQLID },
},
resolve(root, args) {
return models.author.destroy({where: {id: args.id}});
}
};
31 changes: 31 additions & 0 deletions graphql/mutations/author/updateAuthor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
GraphQLID,
GraphQLString,
GraphQLNonNull,
GraphQLInputObjectType
} from 'graphql';

import models from '../../../models/index.js';
import Author from '../../types/author.js';

//working
export default {
type: Author,
name: 'updateAuthor',
args: {
id: { type: GraphQLID },
input: {type: authorInput }
},
resolve(root, {id, input}) {
return models.author.update({name: input.name, last_name: input.last_name}, {where: {id: id}});

}
};

const authorInput = new GraphQLInputObjectType({
name: 'updateAuthorInputType',
fields: () => ({
name: { type: GraphQLString },
last_name: { type: GraphQLString }
})
})
14 changes: 13 additions & 1 deletion graphql/mutations/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import createAuthor from './author/create.js';
import createAuthor from './author/createAuthor.js';
import updateAuthor from './author/updateAuthor.js';
import destroyAuthor from './author/destroyAuthor.js';

import addQuoteToAuthor from './quote/addQuoteToAuthor.js';
import destroyQuote from './quote/destroyQuote.js';
import updateQuote from './quote/updateQuote.js';


export default {
createAuthor,
updateAuthor,
destroyAuthor,
addQuoteToAuthor,
destroyQuote,
updateQuote
};
21 changes: 21 additions & 0 deletions graphql/mutations/quote/addQuoteToAuthor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
GraphQLID,
GraphQLString,
GraphQLNonNull,
GraphQLInputObjectType
} from 'graphql';

import models from '../../../models/index.js';
import Quote from '../../types/quote.js';

export default {
type: Quote,
name: 'addQuote',
args: {
author_id: { type: GraphQLID },
quote: { type: GraphQLString }
},
resolve(root, {author_id, quote}) {
return models.quote.create({author_id: author_id, quote: quote});
}
};
19 changes: 19 additions & 0 deletions graphql/mutations/quote/destroyQuote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
GraphQLID,
GraphQLNonNull,
GraphQLInputObjectType
} from 'graphql';

import models from '../../../models/index.js';
import Quote from '../../types/quote.js';

export default {
type: Quote,
name: 'destroyQuote',
args: {
id: { type: GraphQLID },
},
resolve(root, args) {
return models.quote.destroy({where: {id: args.id}});
}
};
22 changes: 22 additions & 0 deletions graphql/mutations/quote/updateQuote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
GraphQLID,
GraphQLString,
GraphQLNonNull,
GraphQLInputObjectType
} from 'graphql';

import models from '../../../models/index.js';
import Quote from '../../types/quote.js';

export default {
type: Quote,
name: 'updateQuote',
args: {
id: { type: GraphQLID },
quote: { type: GraphQLString },
},
resolve(root, args) {
return models.quote.update({quote: args.quote}, {where: {id: args.id}});

}
};
2 changes: 1 addition & 1 deletion graphql/types/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default new GraphQLObjectType({
resolve(author) {
return models.quote.findAll({ where: { author_id: author.id } });
}
}
},
};
}
});
Loading