Expanded GraphQL API with scenes entities and actors.
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import { parseResolveInfo } from 'graphql-parse-resolve-info';
|
||||
|
||||
import {
|
||||
fetchEntities,
|
||||
fetchEntitiesById,
|
||||
} from '../entities.js';
|
||||
|
||||
import { getIdsBySlug } from '../cache.js';
|
||||
|
||||
export async function fetchEntitiesApi(req, res) {
|
||||
const entities = await fetchEntities(req.query);
|
||||
|
||||
@@ -13,25 +17,37 @@ export const entitiesSchema = `
|
||||
extend type Query {
|
||||
entities(
|
||||
query: String
|
||||
type: String
|
||||
order: [String]
|
||||
limit: Int! = 30
|
||||
page: Int! = 1
|
||||
): EntitiesResult
|
||||
|
||||
entity(
|
||||
id: Int!
|
||||
slug: String!
|
||||
): Entity
|
||||
|
||||
entitiesBySlug(
|
||||
slugs: [String]!
|
||||
): [Entity]
|
||||
|
||||
entitiesById(
|
||||
ids: [Int]!
|
||||
): [Entity]
|
||||
}
|
||||
|
||||
type EntitiesResult {
|
||||
nodes: [Entity]
|
||||
total: Int
|
||||
}
|
||||
|
||||
type Entity {
|
||||
id: Int!
|
||||
name: String
|
||||
slug: String
|
||||
url: String
|
||||
type: String
|
||||
parent: Entity
|
||||
children: [Entity]
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -43,8 +59,17 @@ export async function fetchEntitiesGraphql(query, _req) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchEntitiesByIdGraphql(query, _req) {
|
||||
const [entity] = await fetchEntitiesById([query.id]);
|
||||
export async function fetchEntitiesByIdGraphql(query, req, info) {
|
||||
const entityIds = query.ids || await getIdsBySlug([].concat(query.slug, query.slugs).filter(Boolean), 'entities');
|
||||
const parsedContext = parseResolveInfo(info);
|
||||
|
||||
return entity;
|
||||
const entities = await fetchEntitiesById(entityIds, {
|
||||
includeChildren: Object.hasOwn(parsedContext.fieldsByTypeName.Entity, 'children'),
|
||||
});
|
||||
|
||||
if (query.slugs || query.ids) {
|
||||
return entities;
|
||||
}
|
||||
|
||||
return entities[0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user