enum OrderStatus {
NEW
PROCESSING
COMPLETED
CANCELLED
}
type Order {
id: ID!
date: Date!
status: OrderStatus!
items: [OrderItem!]!
client: Client!
totalAmount: String!
}
type Order {
id: ID!
date: Date!
status: OrderStatus!
items: [OrderItem!]!
client: Client!
totalAmount: String!
}
scalar Date
enum OrderStatus {
NEW
PROCESSING
COMPLETED
CANCELLED
}
type OrderItem {
id: ID!
product: Product!
quantity: Int!
price: String!
subtotal: String!
}
type Client {
id: ID!
name: String!
email: String!
phone: String!
address: String
}
type Product {
id: ID!
name: String!
description: String
price: String!
category: ID!
}
type Product {
id: ID!
name: String!
description: String
price: String!
category: ID!
expirationDate: String
warrantyPeriod: String
}
type FoodProduct {
id: ID!
name: String!
description: String
price: String!
category: ID!
expirationDate: String!
}
type NonFoodProduct {
id: ID!
name: String!
description: String
price: String!
category: ID!
warrantyPeriod: String!
}
interface Product {
id: ID!
name: String!
description: String
price: String!
category: ID!
}
type FoodProduct implements Product {
id: ID!
name: String!
description: String
price: String!
category: ID!
# Дополнительные поля
expirationDate: String!
}
type NonFoodProduct implements Product {
id: ID!
name: String!
description: String
price: String!
category: ID!
# Дополнительные поля
warrantyPeriod: String!
}
{
products {
id
name
price
description
... on FoodProduct {
expirationDate
}
... on NonFoodProduct {
warrantyPeriod
}
}
}
type ProductItem {
id: ID!
product: Product!
quantity: Int!
price: String!
subtotal: String!
}
type ServiceItem {
id: ID!
service: Service!
duration: Int!
date: String!
price: String!
subtotal: String!
}
union OrderLineItem = ProductItem | ServiceItem
type Order {
id: ID!
date: Date!
status: OrderStatus!
items: [OrderLineItem!]!
client: Client!
totalAmount: String!
}
{
order(id: "123") {
id
date
status
items {
... on ProductItem {
id
product {
name
}
quantity
price
}
... on ServiceItem {
id
service {
name
}
duration
date
price
}
}
totalAmount
}
}
input CreateOrderInput {
clientId: ID!
items: [OrderItemInput!]!
comment: String
}
input OrderItemInput {
productId: ID!
quantity: Int!
}
type Order {
id: ID!
date: Date!
status: OrderStatus!
items: [OrderLineItem!]!
client: Client!
totalAmount: String!
partnerIds: [Int!]! # Массив целых чисел (ID поставщиков)
}
type OrderConnection {
edges: [OrderEdge]
pageInfo: PageInfo!
}
type OrderEdge {
node: Order
cursor: String!
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
type OrderConnection {
edges: [OrderEdge]
pageInfo: PageInfo!
totalCount: Int! # Общее количество элементов
}
type OrderEdge {
node: Order
cursor: String!
hasReviewed: Boolean! # Оставил ли пользователь отзыв
}
type Client {
id: ID!
name: String!
orders: OrderConnection! # Соединение с заказами с поддержкой пагинации
}
type Query {
order(id: ID!): Order!
}
{
order(id: "123") {
id
date
status
totalAmount
}
}
type Query {
orders(
id: ID
orderStatus: OrderStatus
itemNames: [String!]
): OrderConnection!
}
type Query {
IsCompletedOrder(id: ID!): Boolean!
}
# Корневой тип запроса
type Query {
# Пагинируемый список продуктов
products(first: Int, after: String): ProductConnection!
}
# Интерфейс для продуктов
interface Product {
id: ID!
name: String!
price: Float!
description: String
}
# Типы продуктов
type FoodProduct implements Product {
id: ID!
name: String!
price: Float!
description: String
expirationDate: Date!
}
type NonFoodProduct implements Product {
id: ID!
name: String!
price: Float!
description: String
warrantyPeriod: Int!
}
# Connection для интерфейса Product
type ProductConnection {
edges: [ProductEdge]
pageInfo: PageInfo!
totalCount: Int!
}
type ProductEdge {
node: Product # Обратите внимание: node имеет тип интерфейса Product
cursor: String!
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
scalar Date
{
products(first: 10, after: "cursor123") {
totalCount
pageInfo {
hasNextPage
endCursor
}
edges {
cursor
node {
id
name
price
# Используем условные фрагменты для получения полей конкретных типов
... on FoodProduct {
expirationDate
}
... on NonFoodProduct {
warrantyPeriod
}
}
}
}
}
type Query {
client(id: ID!): Client
}
type Client {
id: ID!
name: String!
# Вложенное поле
orders(
# Фильтр по статусу
status: OrderStatus,
# Поле для сортировки
sortBy: OrderSortField,
# Направление сортировки
sortDirection: SortOrder
): [Order!]!
}
enum OrderStatus {
NEW
PROCESSING
COMPLETED
CANCELLED
}
enum OrderSortField {
DATE
}
enum SortOrder {
ASC
DESC
}
type Query {
client(id: ID!): Client
orders(clientId: ID!): [Order!]!
}
query($clientId: ID!) {
# Получение данных клиента
client(id: $clientId) {
id
name
email
phone
}
# Получение заказов клиента
orders(clientId: $clientId ) {
id
date
status
totalAmount
}
}
# Переменные
{
"clientId": "CLT-123"
}
input OrderItemInput {
productId: ID!
quantity: Int!
}
type Mutation {
createOrder(
clientId: ID!
items: [OrderItemInput!]!
comment: String
): Order!
}
input CreateOrderInput {
clientId: ID!
items: [OrderItemInput!]!
comment: String
}
input OrderItemInput {
productId: ID!
quantity: Int!
}
type Mutation {
createOrder(input: CreateOrderInput!): Order!
}
mutation($input: CreateOrderInput!) {
createOrder(input: $input) {
id
date
status
client {
name
phone
}
items {
product {
name
price
}
quantity
subtotal
}
totalAmount
}
}
# Пример переменных
{
"input": {
"clientId": "CLT-123",
"items": [
{
"productId": "PROD-1",
"quantity": 2
},
{
"productId": "PROD-2",
"quantity": 1
}
],
"comment": "Доставка до 18:00"
}
}
type Mutation {
importOrders(input: ImportOrdersInput!): Boolean!
}
type Mutation {
importOrders(input: ImportOrdersInput!): ImportOrdersResult!
}
type ImportOrdersResult {
success: Boolean!
#ID созданных заказов
successfulOrders: [ID!]!
}
{
"errors": [
{
"message": "Заказ не найден",
"locations": [{ "line": 3, "column": 7 }],
"path": ["createOrder"],
"extensions": {
"code": "NOT_FOUND",
"details": "Order with id 123 not found"
}
}
],
"data": null
}
union CreateOrderResult = CreateOrderSuccess | CreateOrderError
type CreateOrderSuccess {
order: Order!
}
type CreateOrderError {
code: String!
message: String!
field: String
}
# Мутация
type Mutation {
createOrder(input: CreateOrderInput!): CreateOrderResult!
}
type OrderStatusUpdate {
orderId: ID!
oldStatus: OrderStatus!
newStatus: OrderStatus!
updatedAt: String!
}
type Subscription {
orderStatusChanged(orderId: ID!): OrderStatusUpdate!
}
query GetOrder($orderId: ID!) {
order(id: $orderId) {
id
date
status
totalAmount
}
}
# Переменные
{
"orderId": "123"
}
query GetDashboardData {
# Заказы с разными статусами
newOrders: orders(status: NEW, limit: 5) {
id
date
totalAmount
client {
name
}
}
completedOrders: orders(status: COMPLETED, limit: 5) {
id
date
totalAmount
client {
name
}
}
# Определяем переиспользуемые фрагменты
fragment ClientInfo on Client {
id
name
email
phone
address
}
fragment OrderSummary on Order {
id
date
status
totalAmount
}
fragment OrderItemDetails on OrderItem {
id
quantity
price
subtotal
product {
id
name
price
description
}
}
# Используем фрагменты в запросе
query GetOrderData($orderId: ID!) {
# Полная информация о заказе
order(id: $orderId) {
...OrderSummary
client {
...ClientInfo
}
items {
...OrderItemDetails
}
}
# Список последних заказов того же клиента
recentOrders: orders(limit: 5) {
...OrderSummary
client {
name # Только имя для списка
}
}
}
query GetClient($withAddress: Boolean!) {
client(id: "CLT-123") {
name
email
address @include(if: $withAddress)
}
}
enum OrderStatus {
NEW
PROCESSING
COMPLETED
CANCELLED @deprecated(reason: "Use COMPLETED instead")
}
scalar DateTime @specifiedBy(url: "<https://tools.ietf.org/html/rfc3339>")
# Клиент точно знает: ISO 8601 формат "2023-12-25T10:30:00Z"
type Order {
id: ID!
date: Date!
status: OrderStatus!
items: [OrderItem!]!
client: Client!
totalAmount: String!
}
scalar Date
enum OrderStatus {
NEW
PROCESSING
COMPLETED
CANCELLED
}
type OrderItem {
id: ID!
product: Product!
quantity: Int!
price: String!
subtotal: String!
}
type Client {
id: ID!
name: String!
email: String!
phone: String!
address: String
}
type Product {
id: ID!
name: String!
description: String
price: String!
category: ID!
}
type Query {
orders(
id: ID
orderStatus: OrderStatus
itemNames: [String!]
): OrderConnection!
}