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

graphql-2-json-schema

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-2-json-schema - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

2

CHANGELOG.md

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

## [0.4.0](https://github.com/wittydeveloper/graphql-to-json-schema/compare/v0.3.1...v0.4.0) (2021-01-24)
### [0.3.1](https://github.com/wittydeveloper/graphql-to-json-schema/compare/v0.3.1-0...v0.3.1) (2021-01-21)

@@ -7,0 +9,0 @@

11

dist/lib/reducer.js

@@ -8,7 +8,8 @@ "use strict";

var getRequiredFields = function (fields) {
return lodash_1.map(lodash_1.filter(fields, function (f) {
return typeGuards_1.isIntrospectionListTypeRef(f.type)
? typeGuards_1.isNonNullIntrospectionType(f.type.ofType)
: typeGuards_1.isNonNullIntrospectionType(f.type);
}), function (f) { return f.name; });
return lodash_1.reduce(fields, function (acc, f) {
if (typeGuards_1.isNonNullIntrospectionType(f.type)) {
acc.push(f.name);
}
return acc;
}, []);
};

@@ -15,0 +16,0 @@ exports.getRequiredFields = getRequiredFields;

@@ -6,3 +6,3 @@ "use strict";

var getTodoSchemaIntrospection = function () {
var schema = graphql_1.buildSchema("\n \"A ToDo Object\"\n type Todo {\n \"A unique identifier\"\n id: String!\n name: String!\n completed: Boolean\n color: Color\n \"A list containing colors that cannot contain nulls\"\n colors: [Color!]!\n }\n\n \"\"\"\n A type that describes ToDoInputType. Its description might not\n fit within the bounds of 80 width and so you want MULTILINE\n \"\"\"\n input TodoInputType {\n name: String!\n completed: Boolean\n color: Color=RED\n }\n\n enum Color {\n \"Red color\"\n RED\n \"Green color\"\n GREEN\n }\n\n type Query {\n todo(\n \"todo identifier\"\n id: String!\n isCompleted: Boolean=false\n ): Todo!\n todos: [Todo!]!\n }\n\n type Mutation {\n update_todo(id: String!, todo: TodoInputType!): Todo\n create_todo(todo: TodoInputType!): Todo\n }\n");
var schema = graphql_1.buildSchema("\n \"A ToDo Object\"\n type Todo {\n \"A unique identifier\"\n id: String!\n name: String!\n completed: Boolean\n color: Color\n \"A required list containing colors that cannot contain nulls\"\n requiredColors: [Color!]!\n \"A non-required list containing colors that cannot contain nulls\"\n optionalColors: [Color!]\n }\n\n \"\"\"\n A type that describes ToDoInputType. Its description might not\n fit within the bounds of 80 width and so you want MULTILINE\n \"\"\"\n input TodoInputType {\n name: String!\n completed: Boolean\n color: Color=RED\n }\n\n enum Color {\n \"Red color\"\n RED\n \"Green color\"\n GREEN\n }\n\n type Query {\n todo(\n \"todo identifier\"\n id: String!\n isCompleted: Boolean=false\n requiredStatuses: [String!]!\n optionalStatuses: [String!]\n ): Todo!\n todos: [Todo!]!\n }\n\n type Mutation {\n update_todo(id: String!, todo: TodoInputType!): Todo\n create_todo(todo: TodoInputType!): Todo\n }\n");
var result = graphql_1.graphqlSync(schema, graphql_1.getIntrospectionQuery());

@@ -28,5 +28,17 @@ return {

id: { type: 'string', description: 'todo identifier' },
isCompleted: { type: 'boolean', "default": false }
isCompleted: { type: 'boolean', "default": false },
requiredStatuses: {
type: 'array',
items: {
type: 'string'
}
},
optionalStatuses: {
type: 'array',
items: {
type: 'string'
}
}
},
required: ['id']
required: ['id', 'requiredStatuses']
},

@@ -105,9 +117,14 @@ "return": {

color: { $ref: '#/definitions/Color' },
colors: {
description: 'A list containing colors that cannot contain nulls',
requiredColors: {
description: 'A required list containing colors that cannot contain nulls',
type: 'array',
items: { $ref: '#/definitions/Color' }
},
optionalColors: {
description: 'A non-required list containing colors that cannot contain nulls',
type: 'array',
items: { $ref: '#/definitions/Color' }
}
},
required: ['id', 'name', 'colors']
required: ['id', 'name', 'requiredColors']
},

@@ -114,0 +131,0 @@ Color: {

@@ -31,12 +31,11 @@ import {

export const getRequiredFields = (fields: GetRequiredFieldsType) =>
map(
filter(fields, (f) => {
// Not 100% sure if the GraphQL spec requires that NON_NULL should be
// the parent of LIST if it's both a NON_NULL and LIST field, but this
// should handle either case/implementation
return isIntrospectionListTypeRef(f.type)
? isNonNullIntrospectionType(f.type.ofType)
: isNonNullIntrospectionType(f.type)
}),
(f) => f.name
reduce(
fields,
(acc: string[], f) => {
if (isNonNullIntrospectionType(f.type)) {
acc.push(f.name)
}
return acc
},
[],
)

@@ -43,0 +42,0 @@

{
"name": "graphql-2-json-schema",
"version": "0.3.1",
"version": "0.4.0",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "repository": "git@github.com:wittydeveloper/graphql-to-json-schema.git",

@@ -23,4 +23,6 @@ import {

color: Color
"A list containing colors that cannot contain nulls"
colors: [Color!]!
"A required list containing colors that cannot contain nulls"
requiredColors: [Color!]!
"A non-required list containing colors that cannot contain nulls"
optionalColors: [Color!]
}

@@ -50,2 +52,4 @@

isCompleted: Boolean=false
requiredStatuses: [String!]!
optionalStatuses: [String!]
): Todo!

@@ -82,4 +86,16 @@ todos: [Todo!]!

isCompleted: { type: 'boolean', default: false },
requiredStatuses: {
type: 'array',
items: {
type: 'string',
},
},
optionalStatuses: {
type: 'array',
items: {
type: 'string',
},
},
},
required: ['id'],
required: ['id', 'requiredStatuses'],
},

@@ -158,9 +174,14 @@ return: {

color: { $ref: '#/definitions/Color' },
colors: {
description: 'A list containing colors that cannot contain nulls',
requiredColors: {
description: 'A required list containing colors that cannot contain nulls',
type: 'array',
items: { $ref: '#/definitions/Color' },
},
optionalColors: {
description: 'A non-required list containing colors that cannot contain nulls',
type: 'array',
items: { $ref: '#/definitions/Color' },
},
},
required: ['id', 'name', 'colors'],
required: ['id', 'name', 'requiredColors'],
},

@@ -167,0 +188,0 @@ Color: {

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