Socket
Socket
Sign inDemoInstall

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.0.14 to 0.1.0

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [0.1.0](https://github.com/nicolasdao/graphql-schemax/compare/v0.0.14...v0.1.0) (2021-12-13)
### Features
* Add support for ignoring GraphQL errors ([05b21e7](https://github.com/nicolasdao/graphql-schemax/commit/05b21e716a6e39dff215227ee4f1750e5dd72d81))
### [0.0.14](https://github.com/nicolasdao/graphql-schemax/compare/v0.0.13...v0.0.14) (2021-12-12)

@@ -7,0 +14,0 @@

2

package.json
{
"name": "graphql-schemax",
"version": "0.0.14",
"version": "0.1.0",
"description": "Creates GraphQL string schema from plain JSON objects.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -107,4 +107,8 @@ # GRAPHQL-SCHEMAX

> - [`constructor`](#constructor)
> - [Inline schema definitions signature](#inline-schema-definitions-signature)
> - [Array schema definitions signature](#array-schema-definitions-signature)
> - [Single object signature](#single-object-signature)
> - [`toString`](#tostring)
> - [`add`](#add)
> - [`addIgnoreRules`](#addignorerules)
> - [`addTypeResolutions`](#addtyperesolutions)

@@ -547,4 +551,10 @@ > - [Renaming a type](#renaming-a-type)

)
schema.addIgnoreRules(['Unknown directive'])
console.log(schema.toString())
```
> NOTES: `schema.addIgnoreRules(['Unknown directive'])` is necessary to prevent the `Unknown directive` error to break the compilation. To know more about this topic, please refer to the [`addIgnoreRules`](#addignorerules) section.
Which outputs:

@@ -584,5 +594,9 @@

The `Schemax` class supports an undefined amount of arguments. It supports an inline schema definitions as well as arrays of inline schema definitions.
The `Schemax` class supports multiple signatures:
1. Undefined amount of arguments with support for
- [Inline schema definitions signature](#inline-schema-definitions-signature)
- [Array schema definitions signature](#array-schema-definitions-signature)
2. [Single object to configure various options and the schema definition at the same time](#single-object-signature).
__*Inline schema definitions*__
### Inline schema definitions signature

@@ -636,3 +650,3 @@ ```js

__*Array schema definitions*__
### Array schema definitions signature

@@ -763,2 +777,61 @@ ```js

### Single object signature
```js
import { Schemax } from 'graphql-schemax'
const schema = new Schemax({
ignoreRules:['Unknown directive'],
typeResolutions: [{
def: 'type User',
to: 'type User @some_undefined_directive'
}],
defs:[
'type Project', {
id: 'ID',
name: 'String'
},
'type User', {
id: 'ID',
first_name: 'String',
last_name: 'String'
},
'type Query', {
projects: '[Project]',
users: '[User]'
}
]
})
console.log(schema.toString())
```
Which outputs:
```js
type Project {
id: ID
name: String
}
type Query {
projects: [Project]
users: [User]
}
type User @some_undefined_directive {
id: ID
first_name: String
last_name: String
}
schema {
query: Query
}
```
> NOTES: To learn more about the `ignoreRules` and `typeResolutions`, please refer to the following sections:
> - [`addIgnoreRules`](#addignorerules)
> - [`addTypeResolutions`](#addtyperesolutions)
## `add`

@@ -855,2 +928,37 @@

## `addIgnoreRules`
`graphql-schemax` validates the generated string schema to prevent GraphQL errors. Depending on your use case, you might need to ignore those errors (e.g., undefined directives throw an `Unknown directive` GraphQL error if directives are used but not defined. This happens with global directives such as `@aws_api_key` or `@aws_cognito_user_pools` in AWS AppSync). GraphQL errors can be ignore based on their message using the `addIgnoreRules` API as follow:
```js
import { Schemax } from 'graphql-schemax'
const schema = new Schemax(
'type Project', {
id: 'ID',
name: 'String'
},
'type User @aws_api_key', {
id: 'ID',
first_name: 'String',
last_name: 'String'
},
'type Query', {
projects: '[Project]',
users: '[User]'
})
schema.addIgnoreRules(['Unknown directive'])
console.log(schema.toString())
```
Where `schema.addIgnoreRules(['Unknown directive'])` can be read as follow: _Ignore GraphQL errors whose message starts with 'Unknown directive'_.
This example supports 2 variations:
- `schema.addIgnoreRules([/^Unknown directive/])`: Use regular expression for more advanced string matching.
- `schema.addIgnoreRules([(errMsg => /^Unknown directive/.test(errMsg))])`: Use customfunction for even more advanced string matching.
The values of this API can also be defined in the [Single object signature](#single-object-signature) version of the [Schemax constructor](#constructor).
## `addTypeResolutions`

@@ -888,2 +996,4 @@

}])
// Necessary to prevent the @aws_api_key directive to break the compilation.
schema.addIgnoreRules(['Unknown directive'])

@@ -893,2 +1003,6 @@ console.log(schema.toString())

> NOTES: `schema.addIgnoreRules(['Unknown directive'])` is necessary to prevent the `Unknown directive` error to break the compilation. To know more about this topic, please refer to the [`addIgnoreRules`](#addignorerules) section.
The values of this API can also be defined in the [Single object signature](#single-object-signature) version of the [Schemax constructor](#constructor).
### Merging types

@@ -923,2 +1037,4 @@ #### Keeping the longest type

}])
// Necessary to prevent the @aws_api_key directive to break the compilation.
schema.addIgnoreRules(['Unknown directive'])

@@ -928,2 +1044,4 @@ console.log(schema.toString())

> NOTES: `schema.addIgnoreRules(['Unknown directive'])` is necessary to prevent the `Unknown directive` error to break the compilation. To know more about this topic, please refer to the [`addIgnoreRules`](#addignorerules) section.
Which returns:

@@ -981,2 +1099,4 @@

}])
// Necessary to prevent the @aws_api_key directive to break the compilation.
schema.addIgnoreRules(['Unknown directive'])

@@ -986,2 +1106,4 @@ console.log(schema.toString())

> NOTES: `schema.addIgnoreRules(['Unknown directive'])` is necessary to prevent the `Unknown directive` error to break the compilation. To know more about this topic, please refer to the [`addIgnoreRules`](#addignorerules) section.
Which returns:

@@ -1049,2 +1171,4 @@

}])
// Necessary to prevent the @aws_api_key directive to break the compilation.
schema.addIgnoreRules(['Unknown directive'])

@@ -1054,2 +1178,4 @@ console.log(schema.toString())

> NOTES: `schema.addIgnoreRules(['Unknown directive'])` is necessary to prevent the `Unknown directive` error to break the compilation. To know more about this topic, please refer to the [`addIgnoreRules`](#addignorerules) section.
Which returns:

@@ -1056,0 +1182,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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