Skip to content

CosmicDNA/neo4j-graphql-subscription

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create Conversation

GraphQL Mutation

mutation CreateConversations($input: [ConversationCreateInput!]!) {
  createConversations(input: $input) {
    conversations {
      id
      name
    }
  }
}

Mutation input Variable

{
  "input": [
    {
      "name": "Nice conversation between friends",
      "users": {
        "create": [
          {
            "node": {
              "name": "Brad"
            }
          },
          {
            "node": {
              "name": "Lilly"
            }
          }
        ]
      }
    }
  ]
}

Mutation output

{
  "data": {
    "createConversations": {
      "conversations": [
        {
          "id": "8f8faa32-a565-4b48-bf6b-cd69ab4ee82a",
          "name": "Nice conversation between friends"
        }
      ]
    }
  }
}

Subscribe to messageRelationshipCreated

GraphQL Subscription

subscription OnMessageCreated($where: MessageRelationshipCreatedSubscriptionWhere) {
  messageRelationshipCreated(where: $where) {
    message {
      id
      body
    }
    createdRelationship {
      seen {
        node {
          id
        }
      }
      sender {
        node {
          id
        }
      }
      conversation {
        node {
          id
        }
      }
    }
  }
}

OnMessageCreated Subscription where variable

{
  "where": {
    "createdRelationship": {
      "conversation": {
        "node": {
          "name": "Nice conversation between friends"
        }
      }
    }
  }
}

Create a Message

GraphQL Create Message Mutation

mutation CreateMessages($input: [MessageCreateInput!]!) {
  createMessages(input: $input) {
    messages {
      id
      conversation {
        id
        name
      }
      body
    }
  }
}

Create Message input Variable

{
  "input": [
    {
      "body": "Welcome to you!",
      "conversation": {
        "connect": {
          "where": {
            "node": {
              "name": "Nice conversation between friends"
            }
          }
        }
      },
      "sender": {
        "connect": {
          "where": {
            "node": {
              "name": "Brad"
            }
          }
        }
      }
    }
  ]
}

Create Message Output

{
  "data": {
    "createMessages": {
      "messages": [
        {
          "id": "e4e4d3bc-b2b9-4f3f-8b39-7fbaf089670c",
          "conversation": {
            "id": "8f8faa32-a565-4b48-bf6b-cd69ab4ee82a",
            "name": "Nice conversation between friends"
          },
          "body": "Welcome to you!"
        }
      ]
    }
  }
}

Subscription ouput

// Response received at 12:57:54
{
  "data": {
    "messageRelationshipCreated": {
      "message": {
        "id": "e4e4d3bc-b2b9-4f3f-8b39-7fbaf089670c",
        "body": "Welcome to you!"
      },
      "createdRelationship": {
        "seen": null,
        "sender": null,
        "conversation": {
          "node": {
            "id": "8f8faa32-a565-4b48-bf6b-cd69ab4ee82a"
          }
        }
      }
    }
  }
}

Messages Query

Now running the following query:

query Messages {
  messages {
   id
   body
   sender {
     id
   }
   seen {
     id
   }
  }
}

results in:

{
  "data": {
    "messages": [
      {
        "id": "e4e4d3bc-b2b9-4f3f-8b39-7fbaf089670c",
        "body": "Welcome to you!",
        "sender": {
          "id": "6015e398-3e93-4f61-a035-47abd5b969ad"
        },
        "seen": []
      }
    ]
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published