# graphql-list-fields

> Get a list of fields while resolving a GraphQL query

Latest version **2.0.4** (published 2024-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-list-fields
pnpm add graphql-list-fields
yarn add graphql-list-fields
bun add graphql-list-fields
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2024-02-10 |
| First published | 2016-10-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/graphql-list-fields) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 125 |
| Author | jakepusateri |
| Maintainers | jakepusateri |
| Keywords | ast, schema, fields, graphqlresolveinfo, graphql-js, graphql |

## Links

- npm: https://www.npmjs.com/package/graphql-list-fields
- Repository: https://github.com/jakepusateri/graphql-list-fields
- Homepage: https://github.com/jakepusateri/graphql-list-fields#readme
- Issues: https://github.com/jakepusateri/graphql-list-fields/issues
- npm.io page: https://npm.io/package/graphql-list-fields

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 2.0.4 (latest) — 2024-02-10
- 2.0.3 — 2024-02-03
- 2.0.2 — 2018-03-18
- 2.0.1 — 2018-02-24
- 2.0.0 — 2017-11-04
- 1.1.0 — 2016-11-30
- 1.0.0 — 2016-10-16

## README

# graphql-list-fields
[![npm version](https://badge.fury.io/js/graphql-list-fields.svg)](https://badge.fury.io/js/graphql-list-fields)

When implementing a GraphQL server, it can be useful to know the list of fields being queried on
a given type. This module takes a GraphQLResolveInfo object and returns a list of fields.

Supported features
- Basic Fields
- Fragments
- Inline Fragments
- `@skip` and `@include` directives
- Nested fields into dot.notation

```
npm install --save graphql-list-fields
```

## Usage
```javascript
import getFieldNames from 'graphql-list-fields';

// in some resolve function
resolve(parent, args, context, info) {
    const fields = getFieldNames(info);
    return fetch('/someservice/?fields=' + fields.join(','));
}
```

### Depth Limiting
`getFieldNames` also accepts an optional depth argument, for how many levels deep results should be returned.

The following will only return top-level fields:
```javascript
const fields = getFieldNames(info, 1);
```

---
_Source: https://npm.io/package/graphql-list-fields · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
