Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement syncing module #1

Closed
11 tasks done
weotch opened this issue Apr 28, 2022 · 2 comments
Closed
11 tasks done

Implement syncing module #1

weotch opened this issue Apr 28, 2022 · 2 comments

Comments

@weotch
Copy link
Member

weotch commented Apr 28, 2022

This roughly refactoring algolia-sync.coffee

  • Set configuration via Nuxt module options
  • Figure out how to transpile .gql files so card fragments can be reused
    • Use Webpack's node module to produce chunks to in memory filesystem and then read strings out, like in this demo
    • I think this work goes into @cloak-app/utils as like loadGql(path)
  • Add option for setting the hook to use
  • Add CLI interface (useful for executing while dev-ing the package)
  • Include docs on expectation on where fragments live and what the files are named. And how you need one of query, fragmentPath, or records
  • Use dotenv in cli for use in like the indexName creation
  • Sync Craft records
  • Support mergeShopifyProducts
  • Test syncing from demo site
  • Make a demo showing results
    • Make a helper for prefixing index name

Example configuration option API:

export default {
  cloak: {
    algolia: {
      sync: async ({ $craft, $storefront }) => {

        // Most Craft-only indexes can be built using configuration strings
        // or objects
        const simpleRules = [

          // If just a string, will query Craft for entries of this section name
          // using a fragment from ~/queries/fragments/articles.gql. Index
          // configuration is done through the dashboard.
          'articles',

          // If an object, lets you customize the sync options a bit. TBD what
          // the options are.
          {
            indexHandle: 'blogs',
            section: 'blogPosts',
          },

        ]

        // You can also generate dynamic indices, like for collections
        const collections = await $craft.getEntries({
          query: `
            query {
              entries(section: "collections") {
                ...collection
              }
            }
          ` + collectionFragment
        })
        const productsRules = await Promise.all(collections.map(
          async (collection) => {
            const craftProducts = await $craft.getEntries({
              query: `
                query($collection:String) {
                  entries(section: "products",) {
                    ...product
                  }
                }
              ` + productFragment,
            })
            return {
              indexHandle: `collection-${collection.slug}`,
              settings: {}, // Algolia settings object
              records: await $storefront.mergeProducts(craftProducts)
            }
        }))

        return [ ...simpleRules, ...productsRules ]
      }
    }
  }
}
@weotch
Copy link
Member Author

weotch commented Apr 30, 2022

I think both a function and a simple array should be allowed.

MVP will just be the array mode. Both string and objects are allowed.

It should support multiple cms, each supported cms would have a different default query to fetch records.

Full object shape is like:

  • name (used to build other defaults from, this is what the string form is)
  • query (the gql query that fetches records, there's a default for each cms)
    • fragmentPath (path to fragment to append to default query, should be same fragment used to render entries outside of Algolia, defaults to queries/fragments/name.gql) .. gets appended to the query during unpackaing
  • variables (the gql variables to apply to the query)
  • section (sugar for variables.section, defaults to name)
  • indexName (specify the full index name, defaults to env_site_name)
  • records (not used in mvp, but would be an alternative to specifying the query, this is used instead)
  • settings (Algolia setting block for the index)
  • mergeShopifyProducts (Boolean)

@weotch
Copy link
Member Author

weotch commented May 1, 2022

See nuxt/rfcs#11, maybe we can add a cli command for running one off commands and testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant