npm install # install dependencies in the example folder
npm start # run the example application and open your browser: http://localhost:3000
const UserSchema = new mongoose.Schema({
name: {
type: String
},
age: {
type: Number,
index: true
},
createdAt: Date,
friends: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
],
nums: [Number],
bools: [Boolean],
strings: [String],
removed: Boolean,
body: {
eye: String,
hair: Number
}
});
const User = mongoose.model('User', UserSchema);
- arguments:
id: ID!
query UserQuery {
user(id: "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZmI=") {
id
name
friends(first: 5) {
count
edges {
cursor
node {
id
name
friends {
count
}
}
}
pageInfo {
startCursor
endCursor
hasPreviousPage
hasNextPage
}
}
}
}
{
"data": {
"user": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZmI=",
"name": "User38",
"friends": {
"count": 38,
"edges": [
{
"cursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDU=",
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDU=",
"name": "User0",
"friends": {
"count": 0
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDY=",
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDY=",
"name": "User1",
"friends": {
"count": 1
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDc=",
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDc=",
"name": "User2",
"friends": {
"count": 2
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDg=",
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDg=",
"name": "User3",
"friends": {
"count": 3
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDk=",
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDk=",
"name": "User4",
"friends": {
"count": 4
}
}
}
],
"pageInfo": {
"startCursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDU=",
"endCursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDk=",
"hasPreviousPage": true,
"hasNextPage": true
}
}
}
}
}
- arguments:
id: ID!
query NodeQuery {
user(id: "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZmI=") {
id
... on User {
name
friends(first: 5) {
count
edges {
cursor
node {
id
name
friends {
count
}
}
}
pageInfo {
startCursor
endCursor
hasPreviousPage
hasNextPage
}
}
}
}
}
{
"data": {
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZmI=",
"name": "User38",
"friends": {
"count": 38,
"edges": [
{
"cursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDU=",
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDU=",
"name": "User0",
"friends": {
"count": 0
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDY=",
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDY=",
"name": "User1",
"friends": {
"count": 1
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDc=",
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDc=",
"name": "User2",
"friends": {
"count": 2
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDg=",
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDg=",
"name": "User3",
"friends": {
"count": 3
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDk=",
"node": {
"id": "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDk=",
"name": "User4",
"friends": {
"count": 4
}
}
}
],
"pageInfo": {
"startCursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDU=",
"endCursor": "Y29ubmVjdGlvbi41NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZDk=",
"hasPreviousPage": true,
"hasNextPage": true
}
}
}
}
}
- arguments:
id: [ID], ids: [ID], name: String, age: Float, createdAt: Date, removed: Boolean, _id: ID
query UsersQuery {
users {
id
name
age
body {
eye
}
createdAt
}
}
{
"data": {
"users": [
{
"id": "VXNlcjo1NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDM=",
"name": "User0",
"age": 0,
"body": {
"eye": "blue"
},
"createdAt": "2015-10-19T14:04:44.000Z"
},
{
"id": "VXNlcjo1NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDQ=",
"name": "User1",
"age": 1,
"body": {
"eye": "blue"
},
"createdAt": "2015-10-19T14:04:44.000Z"
},
{
"id": "VXNlcjo1NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDU=",
"name": "User2",
"age": 2,
"body": {
"eye": "blue"
},
"createdAt": "2015-10-19T14:04:44.000Z"
},
{
"id": "VXNlcjo1NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDY=",
"name": "User3",
"age": 3,
"body": {
"eye": "blue"
},
"createdAt": "2015-10-19T14:04:44.000Z"
},
{
"id": "VXNlcjo1NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDc=",
"name": "User4",
"age": 4,
"body": {
"eye": "blue"
},
"createdAt": "2015-10-19T14:04:44.000Z"
}
]
}
}
query ViewerUserQuery {
viewer {
user(id: "VXNlcjo1NjI2MzgwZTU2NWQ2Y2E3NGUzNzc3ZGM=") {
name
age
friends {
count
}
}
}
}
{
"data": {
"viewer": {
"user": {
"name": "User7",
"age": 7,
"friends": {
"count": 7
}
}
}
}
}
query ViewerUsersQuery {
viewer {
users(first: 5, after: "Y29ubmVjdGlvbi41NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDU=") {
edges {
cursor
node {
id
name
friends {
count
}
}
}
pageInfo {
startCursor
endCursor
hasPreviousPage
hasNextPage
}
}
}
}
{
"data": {
"viewer": {
"users": {
"edges": [
{
"cursor": "Y29ubmVjdGlvbi41NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDY=",
"node": {
"id": "VXNlcjo1NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDY=",
"name": "User3",
"friends": {
"count": 3
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDc=",
"node": {
"id": "VXNlcjo1NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDc=",
"name": "User4",
"friends": {
"count": 4
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDg=",
"node": {
"id": "VXNlcjo1NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDg=",
"name": "User5",
"friends": {
"count": 5
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDk=",
"node": {
"id": "VXNlcjo1NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDk=",
"name": "User6",
"friends": {
"count": 6
}
}
},
{
"cursor": "Y29ubmVjdGlvbi41NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NGE=",
"node": {
"id": "VXNlcjo1NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NGE=",
"name": "User7",
"friends": {
"count": 7
}
}
}
],
"pageInfo": {
"startCursor": "Y29ubmVjdGlvbi41NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NDY=",
"endCursor": "Y29ubmVjdGlvbi41NjI0Zjg3Y2ZmZTZmZDMwMzM1NjQ1NGE=",
"hasPreviousPage": true,
"hasNextPage": true
}
}
}
}
}
- arguments:
input: addUserInput!{ name: String, age: Float, createdAt: Date, friends: [ID], nums: [Float], bools: [Boolean], strings: [String], removed: Boolean, clientMutationId: String! }
mutation AddUser {
addUser(input: {clientMutationId: "1", name: "Test", bools: [true, false], friends: ["56264133565d6ca74e377841"]}) {
changedUserEdge {
cursor
node {
_id
id
name
bools
friends {
count
}
}
}
}
}
{
"data": {
"addUser": {
"changedUserEdge": {
"cursor": "Y29ubmVjdGlvbi51bmRlZmluZWQ=",
"node": {
"_id": "56264152565d6ca74e377843",
"id": "VXNlcjo1NjI2NDE1MjU2NWQ2Y2E3NGUzNzc4NDM=",
"name": "Test",
"bools": [
true,
false
],
"friends": {
"count": 1
}
}
}
}
}
}
- arguments:
input: updateUserInput!{ name: String, age: Float, createdAt: Date, friends: [ID], friends_add: [ID], nums: [Float], nums_add: [Float], bools: [Boolean], bools_add: [Boolean], strings: [String], strings_add: [String], removed: Boolean, id: ID!, clientMutationId: String! }
mutation UpdateUser {
updateUser(input: {clientMutationId: "1", id: "VXNlcjo1NjI2NDE1MjU2NWQ2Y2E3NGUzNzc4NDM=", name: "New Name"}) {
changedUser {
id
name
createdAt
}
}
}
{
"data": {
"updateUser": {
"changedUser": {
"id": "VXNlcjo1NjI2NDE1MjU2NWQ2Y2E3NGUzNzc4NDM=",
"name": "New Name",
"createdAt": null
}
}
}
}
Append to array (fieldName_add
):
mutation UpdateUser {
updateUser(input: {clientMutationId: "1", id: "VXNlcjo1NjI2NDE1MjU2NWQ2Y2E3NGUzNzc4NDM=", friends_add: ["VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkYjQ=", "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkYjk="]}) {
changedUser {
id
friends {
count
edges {
node {
name
id
}
}
}
}
}
}
{
"data": {
"updateUser": {
"clientMutationId": "1",
"changedUser": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkYTM=",
"friends": {
"count": 10,
"edges": [
{
"node": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkOWI=",
"name": "User0"
}
},
{
"node": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkOWM=",
"name": "User1"
}
},
{
"node": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkOWQ=",
"name": "User2"
}
},
{
"node": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkOWU=",
"name": "User3"
}
},
{
"node": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkOWY=",
"name": "User4"
}
},
{
"node": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkYTA=",
"name": "User5"
}
},
{
"node": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkYTE=",
"name": "User6"
}
},
{
"node": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkYTI=",
"name": "User7"
}
},
{
"node": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkYjQ=",
"name": "User25"
}
},
{
"node": {
"id": "VXNlcjo1NjZlYmI1MWRmZGRmYjYyYmFjNTRkYjk=",
"name": "User30"
}
}
]
}
}
}
}
}
- arguments:
input: deleteUserInput!{ id: ID!, clientMutationId: String! }
mutation DeleteUser {
deleteUser(input: {clientMutationId: "3", id: "VXNlcjo1NjI2NDE1MjU2NWQ2Y2E3NGUzNzc4NDM="}) {
id
viewer {
users {
count
}
}
}
}
{
"data": {
"deleteUser": {
"id": "VXNlcjo1NjI2NDE1MjU2NWQ2Y2E3NGUzNzc4NDM=",
"viewer": {
"users": {
"count": 206
}
}
}
}
}