# @nhamata/graphql-parser

> parses a GraphQL schema file and generates an object that represents it. Follows 2018 GraphQL schema specification. Has no dependencies

Latest version **1.0.4** (published 2021-09-02) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @nhamata/graphql-parser
pnpm add @nhamata/graphql-parser
yarn add @nhamata/graphql-parser
bun add @nhamata/graphql-parser
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-09-02 |
| First published | 2021-09-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 66.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | NHamata |
| Maintainers | nphamata |
| Keywords | GraphQL, Parser, Code-Generation |

## Links

- npm: https://www.npmjs.com/package/@nhamata/graphql-parser
- Repository: https://github.com/NHamata/graphql-parser
- Homepage: https://github.com/NHamata/graphql-parser#readme
- Issues: https://github.com/NHamata/graphql-parser/issues
- npm.io page: https://npm.io/package/@nhamata/graphql-parser

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2021-09-02
- 1.0.3 — 2021-09-01
- 1.0.2 — 2021-09-01
- 1.0.1 — 2021-09-01
- 1.0.0 — 2021-09-01

## README

# graphql-parser
### Description
This is a minimal, tool with documented source code, and well defined type definitions used to parse graphql schema text according to the 2018 spec. It generates an object that has properties corresponding to the input graphql schema. There are absolutely no dependencies, this utility was made using only the basic node libraries. It is intended to be simple minimal and easy to use so you can extend it to whatever use that fits your needs. Most tools, may not support the full spec and have bloated dependencies, or is nested in a larger module which may not be useful. This module is fairly simple and follows the current graphql 2018 spec including nested directives (which many current popular libraries have difficulty with). It well defines each component via typescript type definitions.
<br/>
<br/>  

### Use Cases
I built this tool so that any commonly used object within the entire scope of a project, such as error events, general logs etc. can also be defined using a graphql schema specification. This standardizes the language throught a project such that the end points and internal domain language throughout the project would be concretely specified using the same specification. 
This is useful as many projects have their own domain specific languages for interacting with components or services, this tool is useful for making a well defined specification of this domain language. This is especially useful for languages that may not have current or feature filled graphql libraries yet, as this tool can be used to generate your own client library based on schema text. The intention of a tool like this is to leverage this utility and extend it for tasks such as code generation for a client, or request/response format checks. General code generators using this parsing library will be made, of course they may not satisfies your needs as generators can be quite specific to a project
<br/>
<br/>
In order to utilize this library you must issue at the root
```
npm install @nhamata/graphql-parser
```
<br/>
then import:

```
import { generateSchemaObject } from '@nhamata/graphql-parser'
```

Then you can use the schema object as you desire. Thats all there is needed, a single funcitonal call

<br/>
<br/>

### Quick Type Defintion Reference, as always the files inside the ./typedefs are the most accurate.

The most basic type that has a single mandatory property
```
NamedComponent:{
name:string
}
```
<br/>
<br/>
Any component extend from NamedComponent (has a mandatory name) can be listed in a

```
NameIndex<ObjectDefinition>
```

<br/>
<br/>
in order to get a Schema object (defined in this repo ./typedefs/graphql-schema.ts the class 'GraphQLSchema') you must pass in the text of a graphql schema file as a string. This object has the following properties
```
    name: string,
    objects?: NameIndex<ObjectDefinition>;
    scalars?: NameIndex<ScalarDefinition>;
    interfaces?: NameIndex<InterfaceDefinition>;
    unions?: NameIndex<UnionDefinition>;
    enums?: NameIndex<EnumDefinition>;
    inputs?: NameIndex<InputDefinition>;
    directiveDefinitions?: NameIndex<DirectiveDefinition>;
```
<br/>
<br/>

This object represents a map whose key is some string (generally the name or id) and value is the defined generic TYPE

```
NameIndex<TYPE>
```

<br/>
<br/>
Each type has the attributes

```
isExtended:boolean
implements?:NameIndex<NamedComponent>; //For object types only
name:string;
fields:NameIndex<TYPE extends InputFieldDefinition|ParameterFieldDefinition>;
directives?:NameIndex<DirectiveAnnotations>;
description?:string
```

<br/>
<br/>

All element based objects (objects that list out items, and do not define fields) will have the same properties as the above except instead of fields it has:

```
elements:NameIndex<TYPE extends Element>;
```
the elements indexed are generally some NamedComponent restricted by an enumeration

<br/>
<br/>
Fields that can contain parameters can contain the properties

```
type:string
name:string
description?:string
directives?:NameIndex<DirectiveAnnotations>;
parameters?:NameIndex<ParameterFieldDefinition>;
```

<br/>
<br/>

otherwise the parmeters is defined as 

```
parameters?:NameIndex<InputFieldDefinition>;
```

<br/>
<br/>

All Parameters that belong to a field that can be parameterized can contain

```
type:string
name:string
directives?:NameIndex<DirectiveAnnotations>;
description?:string
```

<br/>
<br/>
All directive annotations contains the following, note that the parameters can not have descritions. The parameters can also have their own directives.
This allows for nested directives.

```
name:string,
parameters?:NameIndex<ParameterComponent>;
```

<br/>
<br/>
All Parameters of directive annotations and directive definitions can contain. Note that it has no description, and that directives can also be nested in it

```
type:string
name:string
directives?:NameIndex<DirectiveAnnotations>;
```

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