Este archivo contiene ejemplos de queries y mutations que puedes usar con tu API GraphQL de ayuno intermitente.
query GetUsers {
users {
id
email
name
timezone
preferredMethod
createdAt
updatedAt
}
}query GetUser($id: ID!) {
user(id: $id) {
id
email
name
timezone
preferredMethod
fastSessions {
id
startAt
endAt
method
comment
durationMinutes
}
measurements {
id
takenAt
weightKg
bodyFatPercentage
}
reminders {
id
message
sendAt
sent
}
}
}query GetFastSessions {
fastSessions {
id
startAt
endAt
method
comment
durationMinutes
user {
id
name
email
}
}
}query GetMeasurements {
measurements {
id
takenAt
weightKg
bodyFatPercentage
user {
id
name
}
}
}mutation CreateUser($user: UserInput!) {
saveUser(user: $user) {
id
email
name
timezone
preferredMethod
createdAt
}
}Variables:
{
"user": {
"email": "juan@example.com",
"passwordHash": "hashedpassword123",
"name": "Juan Pérez",
"timezone": "America/Argentina/Buenos_Aires",
"preferredMethod": "16:8"
}
}mutation CreateFastSession($fastSession: FastSessionInput!) {
saveFastSession(fastSession: $fastSession) {
id
startAt
endAt
method
comment
durationMinutes
user {
name
}
}
}Variables:
{
"fastSession": {
"user": "USER_ID_HERE",
"startAt": "2024-01-15T18:00:00Z",
"endAt": "2024-01-16T10:00:00Z",
"method": "16:8",
"comment": "Me sentí muy bien durante este ayuno"
}
}mutation CreateMeasurement($measurement: MeasurementInput!) {
saveMeasurement(measurement: $measurement) {
id
takenAt
weightKg
bodyFatPercentage
user {
name
}
}
}Variables:
{
"measurement": {
"user": "USER_ID_HERE",
"takenAt": "2024-01-15T08:00:00Z",
"weightKg": 75.5,
"bodyFatPercentage": 18.2
}
}mutation CreateReminder($reminder: ReminderInput!) {
saveReminder(reminder: $reminder) {
id
message
sendAt
sent
user {
name
}
}
}Variables:
{
"reminder": {
"user": "USER_ID_HERE",
"message": "¡Es hora de comenzar tu ayuno de 16 horas!",
"sendAt": "2024-01-16T18:00:00Z"
}
}mutation UpdateUser($id: ID!, $user: UserInput!) {
updateUser(id: $id, user: $user) {
id
name
preferredMethod
timezone
updatedAt
}
}Variables:
{
"id": "USER_ID_HERE",
"user": {
"name": "Juan Carlos Pérez",
"preferredMethod": "18:6",
"timezone": "America/Argentina/Buenos_Aires"
}
}query GetUserFastSessions($userId: ID!) {
fastSessions(where: { user: $userId }) {
id
startAt
endAt
method
durationMinutes
}
}query GetMeasurementsByDateRange($startDate: DateTime!, $endDate: DateTime!) {
measurements(where: {
takenAt: {
gte: $startDate,
lte: $endDate
}
}) {
id
takenAt
weightKg
bodyFatPercentage
user {
name
}
}
}query GetPendingReminders {
reminders(where: { sent: false }) {
id
message
sendAt
user {
name
email
}
}
}query IntrospectionQuery {
__schema {
types {
name
kind
description
}
}
}-
Autenticación: En un entorno de producción, necesitarás implementar autenticación en el contexto de GraphQL.
-
Validaciones: Simfinity.js aplica automáticamente las validaciones definidas en los tipos.
-
Relaciones: Las relaciones se resuelven automáticamente. Puedes acceder a
userdesdefastSessions,measurementsyreminders. -
Timestamps: Los campos
createdAtyupdatedAtse manejan automáticamente. -
Filtros: Simfinity.js genera automáticamente filtros para todos los campos. Puedes usar operadores como
eq,ne,gt,gte,lt,lte,in,nin, etc. -
Paginación: Simfinity.js incluye soporte automático para paginación con
limit,offset,sort.
Ejemplo de paginación:
query GetPaginatedFastSessions($limit: Int!, $offset: Int!) {
fastSessions(limit: $limit, offset: $offset, sort: "-createdAt") {
id
startAt
endAt
method
}
}