在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):walmartlabs/json-to-simple-graphql-schema开源软件地址(OpenSource Url):https://github.com/walmartlabs/json-to-simple-graphql-schema开源编程语言(OpenSource Language):JavaScript 92.9%开源软件介绍(OpenSource Introduction):json-to-simple-graphql-schemaTransforms JSON input into a GraphQL schema. Try it here Why would I use this?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. Installation:For use as a command-line app use npm i -g @walmartlabs/json-to-simple-graphql-schema For use in a project: npm i @walmartlabs/json-to-simple-graphql-schema Command Line Usage:Pipe in some JSON. Here's a cURL JSON response piped in to this app: curl "https://data.cityofnewyork.us/api/views/kku6-nxdu/rows.json?accessType=DOWNLOAD" \
| npx @walmartlabs/json-to-simple-graphql-schema
Or pipe in some JSON from a JSON file. curl https://data.cityofnewyork.us/api/views/kku6-nxdu/rows.json?accessType=DOWNLOAD > input.json
cat input.json | npx json-to-simple-graphql-schema > output.graphql Optional parameters:
curl https://data.cityofnewyork.us/api/views/kku6-nxdu/rows.json?accessType=DOWNLOAD > input.json
cat input.json | npx json-to-simple-graphql-schema --baseType BaseType --prefix Prefix > output.graphql Usage in front-end JS:import { jsonToSchema } from "@walmartlabs/json-to-simple-graphql-schema/lib";
const schema = jsonToSchema({ jsonInput: '{"name": "Test"}' });
console.log(schema.value); If you need more guidance, have a look at the source for our simple web-ui. Example output: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:
Fun features: duplicate removalConsider this JSON with 2 {
"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:
It kept the Fun features: calls out possible duplicatesConsider 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:
It called out the two types with identical fields. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论