# graphql-custom-field

> A custom GraphQLScalartype to support multiple scalar types

Latest version **1.2.0** (published 2023-12-13) · AGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install graphql-custom-field
pnpm add graphql-custom-field
yarn add graphql-custom-field
bun add graphql-custom-field
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2023-12-13 |
| First published | 2022-06-22 |
| Weekly downloads | 0 |
| License | AGPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 16.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Cherese Eriepa |
| Maintainers | luandro, mixmix, staltz, chereseeriepa, christianbundy, ben-tai |
| Keywords | ahau, graphql, scalar |

## Links

- npm: https://www.npmjs.com/package/graphql-custom-field
- Repository: https://gitlab.com/ahau/lib/graphql/graphql-custom-field
- Homepage: https://gitlab.com/ahau/lib/graphql/graphql-custom-field#readme
- Issues: https://gitlab.com/ahau/lib/graphql/graphql-custom-field/issues
- npm.io page: https://npm.io/package/graphql-custom-field

## Dependencies (1)

- [is-my-json-valid](https://npm.io/package/is-my-json-valid.md) ^2.20.6

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2023-12-13
- 1.1.0 — 2023-12-13
- 1.0.1 — 2023-03-05
- 1.0.0 — 2022-06-22

## README

# graphql-custom-field

Use JavaScript CustomField for fields that can have values of multiple types.

E.g. Can be used if you want to return data which has could have different forms:

```js
// res.data.Profile =>
{
  name: 'Cherese',
  additionalFields: [
    {
      key: 'yearOfBirth',
      value: 1999                  // Int
    },
    {
      key: 'nicknames',
      value: ['Reese', 'Cherry']   // [String]
    }
  ]
}
```

CustomField allows you to do this easily:

```js
type Profile {
  name: String
  additionalFields {
    key: String
    value: CustomField  // String | [String] | Int | Float | Boolean | null
  }
}
```

> NOTE: Can be used in the way for an input types

Supported Types:

- `String`
- `[String]`
- `Int`
- `Float`
- `Boolean`

## Installation

```
npm i --save graphql-custom-field
```

## Usage

Resolvers
```js
const CustomField = require('graphql-custom-field')

const resolvers = {
  CustomField,

  Query: {
    getProfile // ...
  },
  Mutation: {
    saveProfile // ...
  }
}


```

TypeDefs
```js
const { gql } = require('apollo-server')

module.exports = gql`
  # Define scalar type
  scalar CustomField

  type Query {
    getProfile(id: String): Profile
  }

  type Profile {
    id: String
    name: String
    additionalFields: [Field]
  }

  type Field {
    key: ID!
    value: CustomField
  }

  type Mutation {
    saveProfile(input: ProfileInput): Profile
  }

  input ProfileInput {
    id: String
    name: String
    additionalFields: [FieldInput]
  }

  input FieldInput {
    key: String
    value: CustomField
  }
```

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