Giter Site home page Giter Site logo

json-schema-to-graphql-types's Introduction

JSON Schema to GraphQL Types Converter

Greenkeeper badge Build Status Coverage Status

This tools will convert a directory of JSON Schemas into set of GraphQL types. To use it, do the following:

npm install -g @lifeomic/json-schema-to-graphql-types
convert-json-schemas-to-graphql-types <some-dir-with-json-schemas>

When that is run, the tool will output a list of GraphQL types that match the types in the JSON schemas. After generating the types, you'll need to create Query and Mutation types to complete you schema and then add resolvers as needed.

json-schema-to-graphql-types's People

Contributors

cmjarreau avatar dependabot[bot] avatar greenkeeper[bot] avatar indigocarmen avatar jagoda avatar joedimarzio avatar kbaumzie avatar loscm avatar mdlavin avatar morganhuegel avatar overhead525 avatar playdohdoh avatar tommyyork avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json-schema-to-graphql-types's Issues

Add support non global instalation

Add support non global instalation.

npm i @lifeomic/json-schema-to-graphql-types

package.json

{
  "scripts": {
    "convert": "convert-json-schemas-to-graphql-types src/graphql/"
  }
}

Mutation Name for Definitions has the `In` suffix

Most of the Mutation names are outputted in this format

type Mutation {
   TypeName(input: TypeNameIn): String
}

For Mutations that are from a schema's Definitions, they are outputted with the In suffix

type Mutation {
   DefintionTypeNameIn(input: DefinitionTypeNameIn): String
}

This schema is a good testcase

{
  "id": "https://example.com/food.schema.json",
  "type": "object",
  "properties": {
    "fruits": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "vegetables": {
      "type": "array",
      "items": { "$ref": "#/definitions/veggie" }
    }
  },
  "definitions": {
    "veggie": {
      "type": "object",
      "required": [ "veggieName", "veggieLike" ],
      "properties": {
        "veggieName": {
          "type": "string",
          "description": "The name of the vegetable."
        },
        "veggieLike": {
          "type": "boolean",
          "description": "Do I like this vegetable?"
        }
      }
    }
  }
}

type Mutation output

type Mutation {
  DefinitionVeggieIn(input: DefinitionVeggieIn): String
  Food(input: FoodIn): String
}

Error: Failed to convert schema undefined: Error: Must provide name.

I have the following schema (schema.json):

{
  "$schema": "http://json-schema.org/schema#",
  "definitions": {
    "Thing": {
      "$id": "#thing",
      "type": "object",
      "required": [
        "Name"
      ],
      "properties": {
        "Name": {
          "type": "string"
        }
      },
      "additionalProperties": false
    }
  }
}

I see the following when I run convert-json-schemas-to-graphql-types:

$ convert-json-schemas-to-graphql-types  .
Error: Failed to convert schema undefined: Error: Must provide name.
    at convertSchemas (/blah/blah/blah/@lifeomic/json-schema-to-graphql-types/bin/convert-json-schemas-to-graphql-types.js:22:13)
    at convertDir (/blah/blah/blah/@lifeomic/json-schema-to-graphql-types/bin/convert-json-schemas-to-graphql-types.js:54:3)

The tool also fails with the same errors with the examples on this page: http://json-schema.org/learn/miscellaneous-examples.html

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Upgrade to graphql 16

Hello,
Is this package still being maintained?

This works great with Apollo server 2 but it is officially deprecated and end of life later this year.
Later Apollo server versions require graphql 15+ which is not compatible with this repo's graphql 14.

Are there any plans to update it?

An in-range update of yargs is breaking the build 🚨

The dependency yargs was updated from 13.2.2 to 13.2.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

yargs is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 14 commits.

  • a6e67f1 chore(release): 13.2.4
  • fc13476 chore: update standard-verison dependency
  • bf46813 fix(i18n): rename unclear 'implication failed' to 'missing dependent arguments' (#1317)
  • a3a5d05 docs: fix a broken link to MS Terminology Search (#1341)
  • b4f8018 build: add .versionrc that hides test/build
  • 0c39183 chore(release): 13.2.3
  • 08e0746 chore: update deps (#1340)
  • 843e939 docs: make --no- boolean prefix easier to find in the docs (#1338)
  • 84cac07 docs: restore removed changelog of v13.2.0 (#1337)
  • b20db65 fix(deps): upgrade cliui for compatibility with latest chalk. (#1330)
  • c294d1b test: accept differently formatted output (#1327)
  • ac3f10c chore: move .hbs templates into .js to facilitate webpacking (#1320)
  • 0295132 fix: address issues with dutch translation (#1316)
  • 9f2468e doc: clarify parserConfiguration object structure (#1309)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Cannot convert JSON schema when using "$ref" syntax

I have got error as "{ UnknownTypeReference: The referenced type #/definitions/metrics (undefined) is unknown in http://*/_Response.json.metrics".

does this tool support "$ref" syntax?

the schema example as :

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "description": "A json-schema for ***** Response.",
    "id": "http://**/_Response.json",
    "definitions": {
        "metrics": {
            "type": "array",
            "items": {
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "type": {
                        "enum": [
                            "A",
                            "B"
                        ],
                        "type": "string"
                    }
                },
                "required": [
                    "type",
                    "name"
                ],
                "type": "object"
            },
            "default": null
        }
    },
    "type": "object",
    "properties": {
        "metrics": {
            "$ref": "#/definitions/metrics"
        },
        "success": {
            "type": "boolean"
        }
    }
}

Create documentation or examples for responses

Hello! Greatest idea!

Can you add some examples in README.md for your usage? I'm thinking about integrating with requests to API and parser to GraphQL types.

Any documentation, that helps us to contribute with the project.

Incorrect names generated

Input:

{
  ...
  "content": {
     "properties": {
         "content-categories": {
              "$ref": "#/definitions/content-categories"
         }
     }
  }
}

Output:

type SampleContent {
  content-categories: DefinitionContentCategories
}

The name of the field is invalid, according to https://spec.graphql.org/June2018/#Name

Name
/[_A-Za-z][_0-9A-Za-z]*/

AFAICS, dashes are already converted to underscores for enum values. Probably the same should be done for field names. Or maybe make it configurable whether to use camel-case or lower-cased underscores or something else.

Support for optional

Thanks for a great tool.

Encountered something that could be handled:

    "phoneNumber": {
      "type": ["null", "string"]
    },
    "creditRatings": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "items": {
            "required": ["creditRatingAgencyId", "grade"],

That is both phoneNumber and creditRatings are optional.

An in-range update of ava is breaking the build 🚨

The devDependency ava was updated from 2.1.0 to 2.2.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ava is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).
  • coverage/coveralls: First build on greenkeeper/ava-2.2.0 at 100.0% (Details).

Release Notes for 2.2.0

Enhancements

You can now specify an alternative config file, using the --config CLI argument. This is useful if you want to run unit tests separately from integration tests, since you can have a config file specific to your integration tests which specifies different glob patterns. 2dae2bf

Bug fixes

We're now faking the new hasColors() method for better compatibility with Node.js 12. d399797

Node.js 11

We've removed Node.js 11 from our test matrix. You should upgrade to Node.js 12. 90acbb9

All changes

v2.1.0...v2.2.0

Thanks

Thank you @langri-sha, @keyspress, @cdaringe and @okyantoro. We couldn't have done this without you!

Get involved

We welcome new contributors. AVA is a friendly place to get started in open source. We have a great article on getting started contributing and a comprehensive contributing guide.

Commits

The new version differs by 9 commits.

  • 2451484 2.2.0
  • e528ad2 Bump dependencies
  • 2dae2bf Implement --config flag
  • 58b2350 Disable deprecation warnings in reporter tests
  • d399797 Fake hasColors() in worker processes
  • 90acbb9 Stop testing Node.js 11, remove from engines entry
  • 533ee4b Link to VSCode debugging recipe
  • dc91725 Fix grammar in readme
  • 851316f Remove Flow references

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.