0.0.2 • Published 3 years ago

@junglejs/jungle-source-squidex v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

jungle-source-squidex

A datasource plugin for Squidex, a self hosted or managed and open source headless content management system.

Configuration

Please checkout the /example folder.

It is important, to load the datasource asynchrone. This requires to change the default junglejs example app.js(and build.js) file:

getJungleConfig(args)
    .then(jungleConfig => {
        startGraphqlServer(jungleConfig, __dirname,
            () => startAppServer(jungleConfig, app, __dirname,
                () => watchRoutes(jungleConfig, app, __dirname)));
    });

You also have to modify the default junglejs.config.js file for loading the datasource asynchrone:

const load = require("@junglejs/jungle-source-squidex");
const {gql} = require("graphql-request");

// Define your squidex graphql query,
// please use the flatData object
const postSource = {
    name: "post",
    query: gql `
        query {
            queryPostContents {
                flatData {
                    title
                    slug
                    content
                    image {
                        url
                        fileName
                    }
                }
            }
        }
    `,
    options: {
        assets: [
            // this plugin downloads assets from squidex and stores them locally,
            // you have to load the subfields url and fileName
            {source: "image"}
        ],
        markdown: [
            // this plugin allows you to format markdown to html
            {source: "content"}
        ]
    },
    queryArgs: { slug: "String!" }
};

// important, async change:
module.exports = async () => {
    const itemLoader = await load({
        client_id: SQUIDEX_CLIENT_ID,
        client_secret: SQUIDEX_CLIENT_SECRET,
        base_url: SQUIDEX_URL,
        app: SQUIDEX_APP_NAME
    });

    return {
        ...

        dataSources: [
            {
                format: "json",
                name: postSource.name,
                items: await itemLoader(postSource),
                queryArgs: postSource
            }
        ]
    }
}