Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
get-graphql-from-jsonschema
Advanced tools
get-graphql-from-jsonschema gets a GraphQL schema from a JSON schema.
get-graphql-from-jsonschema gets a GraphQL schema from a JSON schema.
Category | Status |
---|---|
Version | |
Dependencies | |
Dev dependencies | |
Build | |
License |
$ npm install get-graphql-from-jsonschema
First you need to add a reference to get-graphql-from-jsonschema to your application:
const getGraphqlFromJsonSchema = require('get-graphql-from-jsonschema').default;
If you use TypeScript, use the following code instead:
import getGraphqlFromJsonSchema from 'get-graphql-from-jsonschema';
To get a GraphQL schema from a JSON schema, call the getGraphqlFromJsonSchema
function and hand over the root name of the schema you want to convert as well as the schema itself. As a result, you get back the root GraphQL type name and, if needed, additional GraphQL type definitions:
const { typeName, typeDefinitions } = getGraphqlFromJsonSchema({
rootName: 'person',
schema: {
type: 'object',
properties: {
firstName: { type: 'string' },
lastName: { type: 'string' },
coordinates: {
type: 'object',
properties: {
latitude: { type: 'number' },
longitude: { type: 'number' }
},
required: [ 'latitude', 'longitude' ],
additionalProperties: false
},
tags: {
type: 'array',
items: {
type: 'object',
properties: {
key: { type: 'string' },
value: { type: 'string' }
},
required: [ 'key', 'value' ],
additionalProperties: false
}
}
},
required: [ 'firstName', 'tags' ],
additionalProperties: false
}
});
console.log(typeName);
// => Person
console.log(typeDefinitions);
// => [
// 'type PersonCoordinates {
// latitude: Float!
// longitude: Float!
// }',
// 'type PersonTags {
// key: String!
// value: String!
// }',
// 'type Person {
// firstName: String!
// lastName: String
// coordinates: PersonCoordinates
// tags: [PersonTags]!
// }'
// ]
If you want to use the generated types as input types for a mutation, additionally provide the direction
option to the call to getGraphqlFromJsonSchema
and set its value to input
:
const { typeName, typeDefinitions } = getGraphqlFromJsonSchema({
rootName: 'person',
schema: {
// ...
},
direction: 'input'
});
To build this module use roboter.
$ npx roboter
FAQs
get-graphql-from-jsonschema gets a GraphQL schema from a JSON schema.
We found that get-graphql-from-jsonschema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.