npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-fgql

v1.0.2

Published

react-fgql is a HOC for integration [fgql](https://github.com/hamavb/fgql) into react application.

Downloads

10

Readme

react-fgql

react-fgql is a HoC for integration fgql into react application

react-fgql is umd (Universal Module Definition) library.

Installation

npm install --save react-fgql fgql

Dependencies

react-fgql depend on fgql to interact with single or multiple graphql endpoint. So you have to install fgql module.

npm install --save fgql

API :

react-fgql take care of instantiating fgql and manage single or multiple queries for the warped component. it allow you to declaratively define multiple queries and related data processing. Then deliver required data and states as props.

react-fgl expose one class createContainer.

QueryObject

QueryObject is a class of fgql module. a couple options autoFetch and mapDataToProps are added to QueryObject that are react-fgql specifics. also regular fetchInterval parameter can be a function that return a number. if fetchInterval value is greater then 0, react-fgql starts fetching immediatly and sequentially each X ms when HoC is mounted.

// ...
var Queries = {
  getUsers: {
    //...
    // autoFetch: false // default
    autoFetch: (ownerProps) => ownerProps.autoFetch,
    mapDataToProps: (data) => ({
        Users: data.Users,
        UsersCount: data.Users.length
    }),
    // fetchInterval: 0 // default
    fetchInterval: (ownerProps) => ownerProps.pullInterval
  }
}

// ...

createContainer

for a EditUser Component, basicly you would need a target User object and a updateUser function to submit changes to the server. createContainer can declaratively provide required actions handler to easly fetch and/or submit data.

Parameters Table :

| Parameter | Type | Default value | | :-------------- | :-------------------------------------------------------------------------- | :------------------- | | Queries | plainObject | undefined | | Component | object | function(ownerProps: object, fgql: object, mapDataToProps: object) | undefined | | endPoint | ?instanceof EndPoint | undefined |

Queries is a plain object. each key is a QueryObject type of fgql modules.

Component is the target component. can be either a React Component or a function that return a React Component.

endPoint is a regular EndPoint instance of fgql modules. each QueryObject can have an endPoint parameter, if none is provided, this one is used.

import React from 'react'
import {EndPoint} from 'fgql'
import {createContainer} from 'react-fgql'

var endPoint = new EndPoint(/* ... */)
var EditUser = class EditUser extends React.Component {/* ... */}

var Queries = {
	getUser: {
		query: ({id}) =>
			`query {
				Viewer {
					User(id: ${id}) {
						id
						fullname 
						email
					}
				}
			}`,
		processResult: (data) => data.Viewer.User,
		// mapDataToProps processed fetch result to props of target component
		mapDataToProps: (data) => ({User: data}),
		// only fire a fetch of 'User' if owner component did not provide it as Props.
		// that's very helpful if component loaded from different places (routes)
		// where some routes provide `User` and others only provide `id`.
		autoFetch: (ownerProps) => !(ownerProps && ownerProps.User)
	},
	updateUser: {
		query: ({id, fullname, email}) =>
			`mutation {
				UpdateUser(
					User: {id: ${id}, fullname: "${fullname}", email: "${email}"}
				) {
					id
					fullname
					email
				}
			}`,
		mapDataToProps: (data) => ({User: data.UpdateUser})
	}
}



var HoC = createContainer(Queries, (ownerProps, fgql, mapDataToProps) => {
  // if `User` object is available (either provided by owner component or auto-fetched) render `EditUser`.
	if (ownerProps && ownerProps.User || mapDataToProps && mapDataToProps.User) {
		return <EditUser {...ownerProps} {...mapDataToProps} fgql={fgql} />
	} else {
    // otherwise, render `Loading` component till the auto-fetch is completed.
		return <label> Loading... </label>
	}
}, endPonit)

// ...

Props Table :

<TargetComponent ...{ownerProps} ...{mapDataToProps} fgql={fgql} />

| Property | Type | | :----------- | :------------------- | | ownerProps | object | | mapDataToProps | object | | fgql | object |

ownerProps is the owner Props passed along by react-fgql.

mapDataToProps is the result of mapDataToProps function.

fgql is a collection of QueryObjects and couple of helper functions such stopAutoFetch, autoFetch and isFetching.

  • stopAutoFetch() is for stoping all running auto-fetch QueryObject.

  • autoFetch() is for starting auto-fetch manually (rather than do it declaratively by setting fetchInterval).

  • isFetching(), return true if any QueryObject is fetching, otherwise false.

Features development

...

Test

npm run test

Contributing

git clone https://github.com/hamavb/react-fgql.git
cd react-fgql
npm install

Criticize or pull requests are very welcome.