Expanded GraphQL API with scenes entities and actors.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { fetchActors } from '../actors.js';
|
||||
import {
|
||||
fetchActors,
|
||||
fetchActorsById,
|
||||
} from '../actors.js';
|
||||
|
||||
export function curateActorsQuery(query) {
|
||||
return {
|
||||
@@ -36,3 +39,101 @@ export async function fetchActorsApi(req, res) {
|
||||
total,
|
||||
});
|
||||
}
|
||||
|
||||
export const actorsSchema = `
|
||||
extend type Query {
|
||||
actors(
|
||||
query: String
|
||||
limit: Int! = 30
|
||||
page: Int! = 1
|
||||
order: [String]
|
||||
): ActorsResult
|
||||
|
||||
actor(
|
||||
id: Int!
|
||||
): Actor
|
||||
|
||||
actorsById(
|
||||
ids: [Int]!
|
||||
): [Actor]
|
||||
}
|
||||
|
||||
type Country {
|
||||
alpha2: String
|
||||
name: String
|
||||
}
|
||||
|
||||
type Location {
|
||||
country: Country
|
||||
city: String
|
||||
state: String
|
||||
}
|
||||
|
||||
type ActorsResult {
|
||||
nodes: [Actor]
|
||||
total: Int
|
||||
}
|
||||
|
||||
type Actor {
|
||||
id: Int!
|
||||
name: String
|
||||
slug: String
|
||||
gender: String
|
||||
dateOfBirth: Date
|
||||
age: Int
|
||||
origin: Location
|
||||
residence: Location
|
||||
height: Int
|
||||
bust: String
|
||||
hip: Int
|
||||
waist: Int
|
||||
naturalBoobs: Boolean
|
||||
eyes: String
|
||||
hairColor: String
|
||||
hasPiercings: Boolean
|
||||
hasTattoos: Boolean
|
||||
tattoos: String
|
||||
piercings: String
|
||||
scenes: Int
|
||||
likes: Int
|
||||
}
|
||||
`;
|
||||
|
||||
function curateGraphqlActor(actor) {
|
||||
return {
|
||||
...actor,
|
||||
age: actor.ageFromBirth,
|
||||
height: actor.height?.metric,
|
||||
weight: actor.weight?.metric,
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchActorsGraphql(query, _req) {
|
||||
const {
|
||||
actors,
|
||||
total,
|
||||
} = await fetchActors(query, {
|
||||
limit: query.limit,
|
||||
page: query.page,
|
||||
order: query.order,
|
||||
aggregateCountries: false,
|
||||
});
|
||||
|
||||
return {
|
||||
nodes: actors.map((actor) => curateGraphqlActor(actor)),
|
||||
total,
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchActorsByIdGraphql(query, _req, _info) {
|
||||
const actors = await fetchActorsById([].concat(query.id, query.ids).filter(Boolean));
|
||||
const curatedActors = actors.map((actor) => curateGraphqlActor(actor));
|
||||
|
||||
console.log(actors);
|
||||
|
||||
if (query.ids) {
|
||||
return curatedActors;
|
||||
}
|
||||
|
||||
return curatedActors[0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user