Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Add mutation through GraphiQL
Browse files Browse the repository at this point in the history
  • Loading branch information
sicktastic committed Nov 3, 2017
1 parent ab4360a commit 436fe38
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
40 changes: 34 additions & 6 deletions graphql/db.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
{
"users": [
{ "id": "23", "firstName": "Bill", "age": 20, "companyId": "1" },
{ "id": "40", "firstName": "Alex", "age": 40, "companyId": "2" },
{ "id": "41", "firstName": "Nick", "age": 40, "companyId": "2" }
{
"id": "23",
"firstName": "Bill",
"age": 20,
"companyId": "1"
},
{
"id": "40",
"firstName": "Alex",
"age": 40,
"companyId": "2"
},
{
"id": "41",
"firstName": "Nick",
"age": 40,
"companyId": "2"
},
{
"firstName": "Anthony",
"age": 26,
"id": "yOTVhLU"
}
],
"companies": [
{ "id": "1", "name": "Apple", "description": "iphone" },
{ "id": "2", "name": "Google", "description": "search" }
{
"id": "1",
"name": "Apple",
"description": "iphone"
},
{
"id": "2",
"name": "Google",
"description": "search"
}
]
}
}
15 changes: 9 additions & 6 deletions graphql/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const {
GraphQLString,
GraphQLInt,
GraphQLSchema,
GraphQLList
GraphQLList,
GraphQLNonNull
} = graphql;

const CompanyType = new GraphQLObjectType({
Expand Down Expand Up @@ -69,17 +70,19 @@ const mutation = new GraphQLObjectType({
addUser: {
type: UserType,
args: {
firstName: { type: GraphQLString },
age: { type: GraphQLInt },
firstName: { type: new GraphQLNonNull(GraphQLString) },
age: { type: new GraphQLNonNull(GraphQLInt) },
companyId: { type: GraphQLString }
},
resolve() {

resolve(parentValue, { firstName, age }) {
return axios.post(`http://localhost:3000/users`, { firstName, age })
.then(res => res.data);
}
}
}
});

module.exports = new GraphQLSchema({
query: RootQuery
query: RootQuery,
mutation
});

0 comments on commit 436fe38

Please sign in to comment.