graphql-schemax
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -5,2 +5,4 @@ # Changelog | ||
### [0.1.2](https://github.com/nicolasdao/graphql-schemax/compare/v0.1.1...v0.1.2) (2022-07-19) | ||
### [0.1.1](https://github.com/nicolasdao/graphql-schemax/compare/v0.1.0...v0.1.1) (2021-12-13) | ||
@@ -7,0 +9,0 @@ |
{ | ||
"name": "graphql-schemax", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Creates GraphQL string schema from plain JSON objects.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
106
README.md
@@ -97,2 +97,4 @@ # GRAPHQL-SCHEMAX | ||
> - [Quick overview](#quick-overview) | ||
> - [Using the same object as a type or input](#using-the-same-object-as-a-type-or-input) | ||
> - [Careful - Enums vs Arrays](#careful---enums-vs-arrays) | ||
> - [Required anonymous types](#required-anonymous-types) | ||
@@ -315,2 +317,106 @@ > - [Required anonymous Type and Input](#required-anonymous-type-and-input) | ||
## Using the same object as a type or input | ||
The sample below shows how to use the `coord` object as a GraphQL type (used in the `Tower` type) and a GraphQL input (used in the `towers` field). | ||
```js | ||
const coord = { | ||
lat:'Float', | ||
long:'Float' | ||
} | ||
const schema = new Schemax( | ||
'type Tower', { | ||
id:'ID!', | ||
name: 'String!', | ||
coord: { ':': coord } | ||
}, | ||
'type Query @aws_cognito_user_pools', { | ||
towers: { | ||
where: { id:'ID', coord:coord }, | ||
':': '[Tower]' | ||
} | ||
} | ||
) | ||
``` | ||
## Careful - Enums vs Arrays | ||
Defining GraphQL enums is done via string arrays: | ||
```js | ||
const schema = new Schemax( | ||
'type Tower', { | ||
id:'ID!', | ||
name: 'String!', | ||
type: ['tall', 'short'] | ||
} | ||
) | ||
``` | ||
Defining GraphQL array types is done via object arrays: | ||
```js | ||
const schema = new Schemax( | ||
'type Tower', { | ||
id:'ID!', | ||
name: 'String!', | ||
type: ['tall', 'short'], | ||
devices: [{ id:'ID', name: 'String'}] | ||
} | ||
) | ||
``` | ||
#### Common mistake: Creating an enum instead of an array type | ||
Let's assume there is an explicit `Device` type, and that a `Tower` typ needs to define a `devices` field as an array of `Device`. The following is __*incorrect*__: | ||
```js | ||
const schema = new Schemax( | ||
'type Device', { | ||
id: 'ID', | ||
name: 'String' | ||
}, | ||
'type Tower', { | ||
id:'ID!', | ||
name: 'String!', | ||
devices: ['Device'] | ||
} | ||
) | ||
``` | ||
In this example, the `Tower.devices` field is a GraphQL enum with one possible value called `Device`. | ||
The __*correct*__ definition is: | ||
```js | ||
const schema = new Schemax( | ||
'type Device', { | ||
id: 'ID', | ||
name: 'String' | ||
}, | ||
'type Tower', { | ||
id:'ID!', | ||
name: 'String!', | ||
devices: '[Device]' | ||
} | ||
) | ||
``` | ||
or, alternatively: | ||
```js | ||
const schema = new Schemax( | ||
'type Device', { | ||
id: 'ID', | ||
name: 'String' | ||
}, | ||
'type Tower', { | ||
id:'ID!', | ||
name: 'String!', | ||
devices: [{ id:'ID', name:'String' }] | ||
} | ||
) | ||
``` | ||
## Required anonymous types | ||
@@ -317,0 +423,0 @@ ### Required anonymous Type and Input |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
350629
1421