How to use the graphile-utils.makeJSONPgSmartTagsPlugin function in graphile-utils

To help you get started, we’ve selected a few graphile-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphile / postgraphile / src / plugins.ts View on Github external
const plugin: Plugin = (builder, options) => {
    function handleTagsError(err: Error): void {
      console.error(`Failed to process smart tags file '${tagsFile}': ${err.message}`);
    }

    const initialTagsJSON: JSONPgSmartTags = JSON5.parse(readFileSync(tagsFile, 'utf8'));

    let tagsListener: null | ((current: Stats, previous: Stats) => void) = null;
    const smartTagsPlugin = makeJSONPgSmartTagsPlugin(initialTagsJSON, updateJSON => {
      if (tagsListener) {
        unwatchFile(tagsFile, tagsListener);
        tagsListener = null;
      }
      if (updateJSON) {
        tagsListener = (_current, _previous): void => {
          readFile(tagsFile, 'utf8', (err, data) => {
            if (err) {
              if (err['code'] === 'ENOENT') {
                updateJSON(null);
              } else {
                handleTagsError(err);
              }
              return;
            }
            try {