@deity/falcon-dynamic-route-extension
This extension provides details about dynamic urls used on the client.
Last updated 2 years ago by deity-io .
OSL-3.0 · Repository · Original npm · Tarball · package.json
$ cnpm install @deity/falcon-dynamic-route-extension 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.0.2                                ...           latest (2 years ago)

2 Versions

  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 3
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |