Skip to content
Snippets Groups Projects
Commit 1500e46d authored by Tarje.Lavik's avatar Tarje.Lavik
Browse files

Refactor api/dump

parent 80ab14e4
No related branches found
No related tags found
No related merge requests found
import {sanityClient as client} from '../../../../../lib/sanity.server'
import { toJSONLD } from "../../lib";
import { getID } from "../../lib/api";
import { context } from "../../lib/context";
import { getID } from "../../lib/queries";
export default async function idHandler(req, res) {
......@@ -9,13 +10,18 @@ export default async function idHandler(req, res) {
} = req
const response = await client.fetch(getID, {id});
const data = await response;
const body = await response;
const result = toJSONLD(data)
const json = toJSONLD(body)
const jsonldData = {
...context,
...json[0],
}
// User with id exists
if (result) {
res.status(200).json(result);
if (jsonldData) {
res.status(200).json(jsonldData);
} else {
res.status(404).json({ message: `Document with id: ${id} not found.` });
}
......
import {sanityClient as client} from '../../../../lib/sanity.server'
import { getDump } from "../lib/api";
import { getDump } from "../lib/queries";
import { toJSONLD } from "../lib";
import { context } from "../lib/context";
export default async function handler(req, res) {
const response = await client.fetch(getDump);
const data = await response;
const body = await response;
const result = toJSONLD(data)
const json = toJSONLD(body)
const json = {
const jsonldData = {
...context,
"@graph": result,
"@graph": json,
};
res.status(200).json(json);
res.status(200).json(jsonldData);
}
File moved
import sanityClient from '@sanity/client'
import sanityImage from '@sanity/image-url'
const options = {
// Find your project ID and dataset in `sanity.json` in your studio project
dataset: 'production',
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
useCdn: process.env.NODE_ENV === 'production',
// useCdn == true gives fast, cheap responses using a globally distributed cache.
// Set this to false if your application require the freshest possible
// data always (potentially slightly slower and a bit more expensive).
}
const client = sanityClient(options)
export const imageBuilder = sanityImage(client)
export const previewClient = sanityClient({
...options,
useCdn: false,
token: process.env.SANITY_API_TOKEN,
})
export default client
import {sanityClient as client} from '../../../../../lib/sanity.server'
import * as jsonld from "jsonld";
import { toJSONLD } from "../../lib";
import { context } from "../../lib/context";
import * as jsonld from "jsonld";
import { getID } from "../../lib/api";
import { getID } from "../../lib/queries";
export default async function rdfIdHandler(req, res) {
const {
......@@ -10,16 +10,16 @@ export default async function rdfIdHandler(req, res) {
} = req
const response = await client.fetch(getID, {id});
const data = await response;
const body = await response;
const result = toJSONLD(data)
const json = toJSONLD(body)
const json = {
const jsonldData = {
...context,
...result[0],
...json[0],
};
const nquads = await jsonld.toRDF(json, { format: "application/n-quads" });
const nquads = await jsonld.toRDF(jsonldData, { format: "application/n-quads" });
// User with id exists
if (nquads) {
......
import {sanityClient as client} from '../../../../lib/sanity.server'
import * as jsonld from "jsonld";
import { toJSONLD } from "../lib";
import { context } from "../lib/context";
import * as jsonld from "jsonld";
import { getDump } from "../lib/api";
import { getDump } from "../lib/queries";
export default async function rdfHandler(req, res) {
const response = await client.fetch(getDump);
const data = await response;
const response = await client.fetch(getDump)
const body = await response;
const result = toJSONLD(data)
const json = toJSONLD(body)
const json = {
const jsonldData = {
...context,
"@graph": [...result],
"@graph": [...json],
};
const nquads = await jsonld.toRDF(json, { format: "application/n-quads" });
const nquads = await jsonld.toRDF(jsonldData, { format: "application/n-quads" })
res.status(200).send(nquads);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment