Expanded GraphQL API with scenes entities and actors.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { format } from 'date-fns';
|
||||
|
||||
import {
|
||||
graphql,
|
||||
buildSchema,
|
||||
@@ -16,6 +18,12 @@ import {
|
||||
fetchEntitiesByIdGraphql,
|
||||
} from './entities.js';
|
||||
|
||||
import {
|
||||
actorsSchema,
|
||||
fetchActorsGraphql,
|
||||
fetchActorsByIdGraphql,
|
||||
} from './actors.js';
|
||||
|
||||
const schema = buildSchema(`
|
||||
type Query {
|
||||
movies(
|
||||
@@ -26,6 +34,7 @@ const schema = buildSchema(`
|
||||
scalar Date
|
||||
|
||||
${scenesSchema}
|
||||
${actorsSchema}
|
||||
${entitiesSchema}
|
||||
`);
|
||||
|
||||
@@ -40,6 +49,17 @@ const DateTimeScalar = new GraphQLScalarType({
|
||||
},
|
||||
});
|
||||
|
||||
const DateScalar = new GraphQLScalarType({
|
||||
name: 'Date',
|
||||
serialize(value) {
|
||||
if (value instanceof Date) {
|
||||
return format(value, 'yyyy-MM-dd');
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
});
|
||||
|
||||
export async function graphqlApi(req, res) {
|
||||
const data = await graphql({
|
||||
schema,
|
||||
@@ -47,12 +67,19 @@ export async function graphqlApi(req, res) {
|
||||
variableValues: req.body.variables,
|
||||
resolvers: {
|
||||
DateTimeScalar,
|
||||
DateScalar,
|
||||
},
|
||||
rootValue: {
|
||||
scenes: async (query) => fetchScenesGraphql(query, req),
|
||||
scene: async (query) => fetchScenesByIdGraphql(query, req),
|
||||
scenesById: async (query) => fetchScenesByIdGraphql(query, req),
|
||||
actors: async (query) => fetchActorsGraphql(query, req),
|
||||
actor: async (query, args, info) => fetchActorsByIdGraphql(query, req, info),
|
||||
actorsById: async (query, args, info) => fetchActorsByIdGraphql(query, req, info),
|
||||
entities: async (query) => fetchEntitiesGraphql(query, req),
|
||||
entity: async (query) => fetchEntitiesByIdGraphql(query, req),
|
||||
entity: async (query, args, info) => fetchEntitiesByIdGraphql(query, req, info),
|
||||
entitiesBySlug: async (query, args, info) => fetchEntitiesByIdGraphql(query, req, info),
|
||||
entitiesById: async (query, args, info) => fetchEntitiesByIdGraphql(query, req, info),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user