Scalar Types: Basic data types (e.g., Int, Float, String, Boolean, ID).
Object Types: Represent a kind of object you can fetch from your service, and what fields it has.
Example:
type User {
id: ID!
name: String!
email: String!
posts: [Post]
}
Interface Types: Abstract types that let you define fields that multiple types must include.
Example:
interface Character {
id: ID!
name: String!
friends: [Character]
appearsIn: [Episode]!
}
Union Types: Define a type that could be one of many types.
Example:
union SearchResult = Book | Author | Magazine
! that indicates the field cannot return null.[ ] that indicates the field is a list of types.
Example:
type User {
hobbies: [String!]
}
Example:
type Post {
id: ID!
title: String!
author: User!
}
Common Directives:
@deprecated: Indicates that a field is no longer supported.@include(if: Boolean): Only includes this field in the result if the argument is true.@skip(if: Boolean): Skips this field if the argument is true.Example:
type User {
id: ID!
oldEmail: String @deprecated(reason: "Use `email`.")
email: String!
}
Input Types: Special kinds of object types that allow you to pass objects as arguments.
Example:
input NewUserInput {
name: String!
email: String!
password: String!
}
Enum Types: Allow you to restrict a field to have one of a predefined set of values.
Example:
enum Role {
ADMIN
USER
GUEST
}