0.0.2 • Published 6 years ago

@deity/falcon-dynamic-route-extension v0.0.2

Weekly downloads
-
License
OSL-3.0
Repository
github
Last release
6 years ago

Falcon Dynamic Url Extension

This extension provides details about dynamic urls used on the client.

When user goes to an url that is not defined in React routing then client asks backend for the type of content for that particular url.

Before server asks the extensions for the data it checks whether extensions have ability to provide content for dynamic url. This is do

Example

The simplest example is handling content from shop and blog. Let's say we want to resolve content for '/sport.html'

class ShopExtension {
    getFetchUrlPriority(url) {
        // if url ends with .html then it's highly possible that it should be handed by shop because it might be
        // a product page under url generated by Magento, so give it
        if (url.endsWith('.html')) {
            return 1;
        }
        return 20;
    }

    fetchUrl(obj, args, context, info) {
        // implementation of the resolver
    }
}
class BlogExtension {
    getFetchUrlPriority(url) {
        // return just static value so others can be higher or lower
        return 10;
    }

    fetchUrl(obj, args, context, info) {
        // implementation of the resolver
    }
}

Dynamic Url Extension will try to call method getFetchUrlPriority(url) of both extensions:

  • ShopExtension will return 1
  • BlogExtension will return 10

So in that case Dynamic Url Extension will call ShopExtension.fetchUrl() first (lowest value has higher priority), if that call retur

Requirements

If any extension should handle dynamic routing it should implement both methods:

  • getFetchUrlPriority(url) - accepts url (String) that should be resolved and returns the priority (Number) for the extension
  • fetchUrl(obj, args, context, info) - fetches the data from the remote source. This methods is called with the parameters ApolloServ