get-graphql-from-jsonschema
Advanced tools
Comparing version 5.0.3 to 6.0.0
@@ -5,3 +5,3 @@ "use strict"; | ||
const errors_1 = require("./errors"); | ||
const parseAnyOf_1 = require("./parseAnyOf"); | ||
const parseOneOf_1 = require("./parseOneOf"); | ||
const parseType_1 = require("./parseType"); | ||
@@ -16,4 +16,4 @@ const common_tags_1 = require("common-tags"); | ||
} | ||
else if (schema.anyOf) { | ||
result = parseAnyOf_1.parseAnyOf({ path, schema, direction }); | ||
else if (schema.oneOf) { | ||
result = parseOneOf_1.parseOneOf({ path, schema, direction }); | ||
} | ||
@@ -20,0 +20,0 @@ else { |
@@ -0,1 +1,16 @@ | ||
# [6.0.0](https://github.com/thenativeweb/get-graphql-from-jsonschema/compare/5.0.3...6.0.0) (2020-08-03) | ||
### Features | ||
* Flip usage of oneOf/anyOf, since it was wrong. Add documentation. ([#142](https://github.com/thenativeweb/get-graphql-from-jsonschema/issues/142)) ([d91bfc1](https://github.com/thenativeweb/get-graphql-from-jsonschema/commit/d91bfc11cbd2bebff9d9a1eabb836571a6e5e708)) | ||
### BREAKING CHANGES | ||
* It is impossible to map json schema's anyOf to GraphQL, since multiple | ||
of the given schemas may match. GraphQL only provider exclusionary | ||
union types, which correspond to oneOf in json schema. | ||
So the terms had to be switched. | ||
## [5.0.3](https://github.com/thenativeweb/get-graphql-from-jsonschema/compare/5.0.2...5.0.3) (2020-07-13) | ||
@@ -2,0 +17,0 @@ |
import { Direction } from './Direction'; | ||
import { errors } from './errors'; | ||
import { JSONSchema4 } from 'json-schema'; | ||
import { parseAnyOf } from './parseAnyOf'; | ||
import { parseOneOf } from './parseOneOf'; | ||
import { parseType } from './parseType'; | ||
@@ -19,4 +19,4 @@ import { stripIndent } from 'common-tags'; | ||
result = parseType({ path, schema, direction }); | ||
} else if (schema.anyOf) { | ||
result = parseAnyOf({ path, schema, direction }); | ||
} else if (schema.oneOf) { | ||
result = parseOneOf({ path, schema, direction }); | ||
} else { | ||
@@ -23,0 +23,0 @@ throw new errors.SchemaInvalid(`Structure at '${toBreadcrumb(path)}' not recognized.`); |
{ | ||
"name": "get-graphql-from-jsonschema", | ||
"version": "5.0.3", | ||
"version": "6.0.0", | ||
"description": "get-graphql-from-jsonschema gets a GraphQL schema from a JSON schema.", | ||
@@ -24,4 +24,4 @@ "contributors": [ | ||
"devDependencies": { | ||
"assertthat": "5.1.1", | ||
"roboter": "11.2.6", | ||
"assertthat": "5.2.1", | ||
"roboter": "11.2.13", | ||
"semantic-release-configuration": "1.0.20" | ||
@@ -28,0 +28,0 @@ }, |
@@ -108,2 +108,40 @@ # get-graphql-from-jsonschema | ||
### Using `oneOf` to generate union types | ||
The `oneOf` keyword is supported with a limitation on its use: There must be no other properties on the same level as the `oneOf`. | ||
```javascript | ||
const { typeName, typeDefinitions } = getGraphqlFromJsonSchema({ | ||
rootName: 'foobar', | ||
schema: { | ||
oneOf: [ | ||
{ | ||
type: 'number' | ||
}, | ||
{ | ||
type: 'object', | ||
properties: { | ||
foo: { type: 'string' }, | ||
bar: { type: 'number' } | ||
}, | ||
required: [ 'foo' ], | ||
additionalProperties: false | ||
} | ||
] | ||
} | ||
}); | ||
console.log(typeName); | ||
// => Foobar | ||
console.log(typeDefinitions); | ||
// => [ | ||
// 'type FoobarI1T0 { | ||
// foo: String! | ||
// bar: Float | ||
// }', | ||
// 'union Foobar = Float | FoobarI1T0' | ||
// ] | ||
``` | ||
### Knowing the limitations | ||
@@ -114,3 +152,3 @@ | ||
- The `null` type gets ignored, since it can not be mapped to GraphQL directly. | ||
- The keywords `allOf` and `oneOf` get ignored, since their logic can not be mapped to GraphQL. However, the `anyOf` keyword is supported. | ||
- The keywords `allOf` and `anyOf` get ignored, since their logic can not be mapped to GraphQL. However, the `oneOf` keyword is supported. | ||
@@ -117,0 +155,0 @@ ## Running the build |
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
33190
160