
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
@walmartlabs/json-to-simple-graphql-schema
Advanced tools
Converts a JSON object into a GraphQL schema
Transforms streamed JSON input into a GraphQL schema.
Let's say you want to use an existing REST API in a GraphQL service and expose the data that API provides. You'll need to expose that data in a GraphQL schema. Without this tool, you'll have to slog through the JSON response and manually extract and convert the relevant types to GraphQL schema types. This tool attempts to provide an automated reasonable first-pass at that effort.
No need to install this, use npx
:) If you'd really like to install, you can do:
npm i -g @walmartlabs/json-to-simple-graphql-schema
Pipe in some JSON. Here's a cURL JSON response piped in to this app:
curl https://demo.ckan.org/api/3/action/package_show?id=adur_district_spending \
| npx json-to-simple-graphql-schema
You'll still need to rename the resulting main Type in the schema, unless you like
AutogeneratedMainType
:)
Or pipe in some JSON from a JSON file.
```bash
curl https://demo.ckan.org/api/3/action/package_show?id=adur_district_spending > input.json
cat input.json | npx json-to-simple-graphql-schema > output.graphql
Given this JSON:
{
"id": "some-id-0",
"name": "A fun object",
"subType": {
"id": "some-id-1",
"name": "A fun sub-type"
}
}
This app will send this to stdout:
type SubType {
id: String
name: String,
}
type AutogeneratedMainType {
id: String
name: String
subType: SubType
}
Consider this JSON with 2 color
types:
{
"id": "some-id-0",
"name": "A fun object",
"color": {
"id": "color-id-1",
"name": "Test color"
},
"subType": {
"id": "some-id-1",
"name": "A fun sub-type",
"color": {
"id": "color-id-1",
"name": "Test color",
"hex": "#ff0000"
}
}
}
When piped to this app, the following schema is produced:
type Color {
id: String
name: String
hex: String,
}
type SubType {
id: String
name: String
color: Color,
}
type AutogeneratedMainType {
id: String
name: String
subType: SubType
color: Color
}
It kept the Color
type with more fields.
Consider this JSON with two types containing identical fields:
{
"id": "some-id-0",
"name": "A fun object",
"color": {
"id": "color-id-1",
"name": "Test color"
},
"favoriteColor": {
"id": "color-id-1",
"name": "Test color"
}
}
When piped to this app, the following schema is produced:
type FavoriteColor {
id: String
name: String
}
type Color {
id: String
name: String
}
type AutogeneratedMainType {
id: String
name: String
favoriteColor: FavoriteColor
color: Color
}
# Types with identical fields:
# FavoriteColor Color
It called out the two types with identical fields.
FAQs
Converts a JSON object into a GraphQL schema
The npm package @walmartlabs/json-to-simple-graphql-schema receives a total of 1,073 weekly downloads. As such, @walmartlabs/json-to-simple-graphql-schema popularity was classified as popular.
We found that @walmartlabs/json-to-simple-graphql-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 10 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
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.