Files
DVA-02-Notes/Study/AppSync/GraphQL.md
T
2026-11-02 15:53:54 +00:00

1.1 KiB

GraphQL

GraphQL is an FOSS agnostic query adaptor that allows you to query data from many different data sources. GraphQL is used to build APIs where clients will send a query for nested data. GraphQL mitigates the issue of versioned or rapidly changing APIs compared to REST APIs because you can request the data you want.

GraphQL schemas are written in the GraphQL SDL (Schema Definition Language) composed on:

  • Types. Represent objects and their fields:
type Query {
    me: User
}

type User {
    id: ID
    name: String
}
  • Fields
  • Queries. Define the exact shape of the data needed by the client:
query CurrentUser {
    currentUser {
        name
        age
    }
}
  • Mutations. Allow for data to be create, updated or deleted:
mutation CreateUser($name: String!, $age: Int!) {
    createUser(userName: $name, age: $age) {
        name
        age
    }
}
  • Subscriptions. Supports live updates sent from the server to the client:
subscription {
    newPerson {
        name
        age
    }
}