'use strict';

const { makeExtendSchemaPlugin, gql } = require('graphile-utils');

const schemaExtender = makeExtendSchemaPlugin(_build => ({
    typeDefs: gql`
        extend type Site {
            independent: Boolean @requires(columns: ["parameters"])
        }
    `,
    resolvers: {
        Site: {
            independent(parent, _args, _context, _info) {
                if (!parent.parameters) {
                    return false;
                }

                const parameters = JSON.parse(parent.parameters);

                return !!parameters.independent;
            },
        },
    },
}));

module.exports = [schemaExtender];
