Fixed summary copy button value. Expanded experimental GraphQL API.

This commit is contained in:
2024-08-28 02:06:01 +02:00
parent e727745e7d
commit 24f5597521
3 changed files with 84 additions and 8 deletions

View File

@@ -1,25 +1,48 @@
import { graphql, buildSchema } from 'graphql';
import {
graphql,
buildSchema,
GraphQLScalarType,
} from 'graphql';
import { scenesSchema, fetchScenesGraphql } from './scenes.js';
const schema = buildSchema(`
type Query {
scenes: [Scene]
scenes(
limit: Int = 30
): Result
}
scalar Date
${scenesSchema}
`);
const DateTimeScalar = new GraphQLScalarType({
name: 'DateTime',
serialize(value) {
if (value instanceof Date) {
return value.toISOString();
}
return value;
},
});
export async function graphqlApi(req, res) {
const data = await graphql({
schema,
source: req.body.query,
variableValues: req.body.variables,
resolvers: {
DateTimeScalar,
},
rootValue: {
scenes: async (query) => fetchScenesGraphql(query, req),
},
});
console.log(data);
// console.log(data);
res.send(data);
}