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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tapgiants/field-gql

v1.0.2

Published

FieldGQL uses GraphQL query in order to load the initial data from a server

Readme

What is @tapgiants/field-gql

@tapgiants/field-gql goal is to provide easy way to load the fields data in your form fields.

Installation

Install peer dependencies:

yarn add apollo-boost graphql react-apollo

Install @tapgiants/field-gql

yarn add @tapgiants/field-gql

FieldGQL API

FieldGQL component follows the convetions described in the GraphQL conventions section.

So be sure you follow the list convetions.

Props

name: String

Field name. If valuePath is not provited it will use it as a value of valuePath.

label: String

Field label.

FieldCtxComponent: React.Component

FieldCtxComponent will receive all the passed props to the FieldGQL component. When the data is fetched from the server this component will receive array with the data as an options props.

Oprions format:

[
  { value: 'BG', label: 'Bulgaria' },
  { value: 'BF', label: 'Burkina Faso' },
  { value: 'BI', label: 'Burundi' }
]

valuesQuery: Object

This query will be used in order to fetch the data from a GraphQL server. Query reference.

valueKey: String

A property name in the json collection that will be returned from the server. It will be used in order to fill in the value property in the options prop.

valueLabel: String

A property name in the json collection that will be returned from the server. It will be used in order to fill in the label property in the options prop.

valuePath: String

Example:

// Server response:
{
  data: {
    industries: { // Use `industries` as a `valuePath`.
      list: [ // list key is a part of the GraphQL conventions described bellow.
        {
          id: 'BG', // Use `id` as a `valueKey`
          name: 'Bulgaria' // Use `name` as a `valueLabel`.
        }
      ]
    }
  }
}

FieldGQL example

import React from 'react';
import { ApolloWrapper } from '@tapgiants/graphql';
import FieldGQL from '@tapgiants/field-gql';
import gql from 'graphql-tag';

const INDUSTRIES = gql`
  query {
    industries {
      list {
        id
        name
      }
    }
  }
`;

const Field = ({ name, label, options, onChange }) => (
  <React.Fragment>
    <label>{label}</label>

    <select name={name} onChange={onChange}>
      {options.map(({ value, label }) => <option key={value} value={value}>{label}</option>)}
    </select>
  </React.Fragment>
);

export default () => (
  <ApolloWrapper uri="http://localhost:4001/api">
    <FieldGQL
      name="industries"
      label="Industries"
      valuesQuery={INDUSTRIES}
      valueKey="id"
      valueLabel="name"
      FieldCtxComponent={Field}
      onChange={(e) => console.log(e.target.value)}
    />
  </ApolloWrapper>
);

How to use FieldGQL with the @tapgiants/form

First check Tap Giants form package.

In order FieldGQL to be a part of your form context just set FieldCtxComponent to Tap Giants form field.

FieldGQL with Tap Giants form example

import React from 'react';
import gql from 'graphql-tag';
import Form, { Field, Submit, withForm } from '@tapgiants/form';
import { ApolloWrapper } from '@tapgiants/graphql';
import FieldGQL from '@tapgiants/field-gql';

const INDUSTRIES = gql`
  query {
    industries {
      list {
        id
        name
      }
    }
  }
`;

const COUNTRIES = gql`
  query {
    countries {
      list {
        code
        name
      }
    }
  }
`;

const FormMarkup = ({ formName, ...formikBag }) => (
  <ApolloWrapper uri="http://localhost:4001/api">
    <Form {...formikBag}>
      <h1>{formName}</h1>

      <Field
        name="companyName"
        label="Company Name"
      />

      <FieldGQL
        input="select"
        name="country"
        label="country"
        valuesQuery={COUNTRIES}
        valuePath="countries"
        valueKey="code"
        valueLabel="name"
        FieldCtxComponent={Field}
      />

      <FieldGQL
        input="checkboxGroup"
        name="industries"
        label="Industries"
        valuesQuery={INDUSTRIES}
        valueKey="id"
        valueLabel="name"
        FieldCtxComponent={Field}
      />

      <Submit>Save</Submit>
    </Form>
  </ApolloWrapper>
);

const TapGiantsForm = withForm({
  mapPropsToValues: () => ({ companyName: '', industries: [], country: '' }),
  handleSubmit: (values, formikBag) => {
    const { setSubmitting } = formikBag;

    setSubmitting(false);

    console.log('handleSubmit values: ', values);
    // handleSubmit values: { companyName: "", industries: [], country: '' }

    console.log('handleSubmit formikBag', formikBag);
    // handleSubmit formikBag: check https://jaredpalmer.com/formik/docs/api/withFormik
  }
})(FormMarkup);

export default () => <TapGiantsForm formName="Test Form" />;

GraphQL conventions

Add link to an external repo that describes all the conventions.

Development

Link the package from your target project and run yarn start. This will start the webpacker watcher.

Once you are satisfied with your changes, use yarn publish to push the new version to npmjs.org.