Graphql schema

GraphQL schema is like a blueprint for your data. It defines how your data is structured and how you can interact with it. The schema outlines the types of data available, relationships between them, and the operations (queries and mutations) you can perform.

more about schemas and Types

Main Operations In graphql

  1. query

  2. mutation

  3. subscriptions

  1. query in graphql

    • Purpose: Used to fetch data from the server.

    • What it Does: Retrieves information but doesn't modify any data on the server.

    • Example: Asking for details about a user or a list of products.

query GetUserDetails($userId: ID!) {
  user(id: $userId) {
    id
    name
    email
  }
}
  1. mutation in graphql

    • Purpose: Used to create/delete/update data on the server.

    • What it Does: Performs operations that cause changes on the server, such as creating, updating, or deleting data.

    • Example: Adding a new user, updating a post, or deleting a comment.

mutation UpdatePost($postId: ID!, $input: PostInput!) {
  updatePost(id: $postId, input: $input) {
    id
    title
    content
  }
}
  1. subscriptions in graphql

    [They act like web sockets]

    • Purpose: Used to receive real-time updates when data on the server changes.

    • What it Does: Establishes a long-lived connection to the server, allowing the server to push updates to the client when relevant data changes.

    • Example: Subscribing to receive notifications about new messages in a chat application.

subscription NewMessageNotification($chatRoomId: ID!) {
  newMessage(chatRoomId: $chatRoomId) {
    id
    sender {
      id
      username
    }
    content
  }
}

Last updated