cd ../graphql-api
API reference·GraphQL over HTTP · Strawberry + FastAPI·POST /graphql

GraphQL API

A schema-first GraphQL API: typed Strawberry types, resolver composition into a single Query/Mutation root, and DataLoader batching to kill N+1 queries. Everything below is taken straight from the published source.

// Argument names shown from the resolver source; the live GraphQL Playground at /graphql is the canonical schema.

$ cat schema.graphql

schema.graphql
type UserType {
  id: Int!
  name: String!
  email: String!
}

type PostType {
  id: Int!
  title: String!
  content: String!
  author: UserType!
}

type Query {
  users: [UserType!]!
  posts: [PostType!]!
  post(post_id: Int!): PostType!
}

type Mutation {
  createUser(name: String!, email: String!): UserType!
  createPost(title: String!, content: String!, author_id: Int!): PostType!
  updatePost(post_id: Int!, title: String, content: String): PostType!
  deletePost(post_id: Int!): Boolean!
}

$ cat examples/queries.graphql

examples/queries.graphql
query GetAllPosts {
  posts {
    id
    title
    content
    author {
      id
      name
    }
  }
}

query GetAllUsers {
  users {
    id
    name
    email
  }
}

query GetPostById {
  post(post_id: 3) {
    id
    title
    content
    author {
      id
      name
    }
  }
}

$ cat examples/mutations.graphql

examples/mutations.graphql
mutation {
  createPost(title: "GraphQL Rocks", content: "Really loving this", authorId: 1) {
    id
    title
    author {
      name
    }
  }
}

mutation {
  createUser(name: "Jane Doe", email: "Doe@example.com") {
    id
    name
    email
  }
}

mutation {
  updatePost(id: 1, title: "GraphQL is Awesome", content: "Updated content") {
    id
    title
    content
    author {
      id
      name
      email
    }
  }
}

mutation {
  deletePost(post_id: 1)
}
view source on GitHub