Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-schemax

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-schemax - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

CHANGELOG.md

@@ -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 @@

2

package.json
{
"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": [

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc