All Projects → aweary → Json To Graphql

aweary / Json To Graphql

Licence: mit
Create GraphQL schema from JSON files and APIs

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Json To Graphql

Prisma Auth0 Example
Boilerplate Prisma Startup
Stars: ✭ 184 (-2.65%)
Mutual labels:  graphql
Gatsby Starter Morning Dew
🚀 A Gatsby theme/starter to build lightning-fast blog/websites
Stars: ✭ 186 (-1.59%)
Mutual labels:  graphql
Tipe
🎉 Next Generation API-first CMS for developers. Generate an API-first CMS from a GraphQL schema with offline prototyping and an inline editor
Stars: ✭ 2,157 (+1041.27%)
Mutual labels:  graphql
Smakosh.com
My personal website
Stars: ✭ 185 (-2.12%)
Mutual labels:  graphql
Apollo Offline
An offline toolkit for the Apollo client
Stars: ✭ 186 (-1.59%)
Mutual labels:  graphql
Graphql Engine Heroku
Blazing fast, instant realtime GraphQL APIs on Postgres with fine grained access control, also trigger webhooks on database events.
Stars: ✭ 188 (-0.53%)
Mutual labels:  graphql
Graphql Faker
🎲 Mock or extend your GraphQL API with faked data. No coding required.
Stars: ✭ 2,361 (+1149.21%)
Mutual labels:  graphql
Next Ecommerce
⚡️ Quantum Ecommerce. Made with Next.js | GraphQL | Apollo Server | Apollo Client | SSR
Stars: ✭ 186 (-1.59%)
Mutual labels:  graphql
Fullstack
React/ApolloGraphQL/Node/Mongo demo written in Typescript
Stars: ✭ 12,653 (+6594.71%)
Mutual labels:  graphql
Blog Service
blog service @nestjs
Stars: ✭ 188 (-0.53%)
Mutual labels:  graphql
Graphql Ppx
GraphQL language primitives for ReScript/ReasonML written in ReasonML
Stars: ✭ 185 (-2.12%)
Mutual labels:  graphql
Next React Graphql Apollo Hooks
React, Apollo, Next.js, GraphQL, Node.js, TypeScript high performance boilerplate with React hooks GraphQL implementation and automatic static type generation
Stars: ✭ 186 (-1.59%)
Mutual labels:  graphql
Graphql Spqr Spring Boot Starter
Spring Boot 2 starter powered by GraphQL SPQR
Stars: ✭ 187 (-1.06%)
Mutual labels:  graphql
Hotchocolate
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
Stars: ✭ 3,009 (+1492.06%)
Mutual labels:  graphql
Graphql.js
A Simple and Isomorphic GraphQL Client for JavaScript
Stars: ✭ 2,206 (+1067.2%)
Mutual labels:  graphql
Comunica
📬 A knowledge graph querying framework for JavaScript
Stars: ✭ 183 (-3.17%)
Mutual labels:  graphql
Cf Graphql
Generate a GraphQL schema out of your Contentful space
Stars: ✭ 187 (-1.06%)
Mutual labels:  graphql
Pronote Api
(Tout langage) API compatible Pronote 2020/2021
Stars: ✭ 186 (-1.59%)
Mutual labels:  graphql
React Imgpro
📷 Image Processing Component for React
Stars: ✭ 2,186 (+1056.61%)
Mutual labels:  graphql
Autoserver
Create a full-featured REST/GraphQL API from a configuration file
Stars: ✭ 188 (-0.53%)
Mutual labels:  graphql

DEPRECATED

-- This project is no longer maintained and has fallen severely out of sync with the
-- GraphQL community. Don't use it at all.

json-to-graphql

Generates a GraphQL schema file based on any JSON data

Overview

This package can take in almost* any kind of JSON data and generate a valid GraphQL schema file, including custom types, lists, nullable and non-nullable fields, and deeply nested children.

If passed an array of JSON data it will use that as "training" data to check type consistency and identify if fields are nullable or not.


  • This project is still in pre-release stage and corner cases are sure to arise

Install

$ npm install --save json-to-graphql

Usage

generateSchema(data: json | Array<json>): string

Takes in JSON data (either a singular instance or array) and returns a string containing the schema definitions. You'll likely want to just write this to a file using fs.

import generateSchema from 'json-to-graphql'
import data from './data.json'

const schema = generateSchema(data)
fs.writeFile('schema.js', schema, callback)

example

Say you have the following JSON response from an API

{
  "name": "brandon",
  "id": 1,
  "favorite_color": "teal",
  "job": {
    "type": "web developer",
    "years": 1
  },
  "dogs": ["minnie", "navi"]
}

It includes strings, ints, nested objects, and arrays. Passing this to generateSchema would output the following schema:


const {
    GraphQLBoolean,
    GraphQLString,
    GraphQLInt,
    GraphQLFloat,
    GraphQLObjectType,
    GraphQLSchema,
    GraphQLID,
    GraphQLNonNull
} = require('graphql')


const JobType = new GraphQLObjectType({
    name: 'job',
    fields: {
        type: {
            description: 'enter your description',
            type: new GraphQLNonNull(GraphQLString),
            // TODO: Implement resolver for type
            resolve: () => null,
        },
        years: {
            description: 'enter your description',
            type: new GraphQLNonNull(GraphQLInt),
            // TODO: Implement resolver for years
            resolve: () => null,
        }
    },
});


module.exports = new GraphQLSchema({
    query: new GraphQLObjectType({
        name: 'RootQueryType',
        fields: () => ({
            name: {
                description: 'enter your description',
                type: new GraphQLNonNull(GraphQLString),
                // TODO: Implement resolver for name
                resolve: () => null,
            },
            id: {
                description: 'enter your description',
                type: new GraphQLNonNull(GraphQLID),
                // TODO: Implement resolver for id
                resolve: () => null,
            },
            favorite_color: {
                description: 'enter your description',
                type: new GraphQLNonNull(GraphQLString),
                // TODO: Implement resolver for favorite_color
                resolve: () => null,
            },
            job: {
                description: 'enter your description',
                type: new GraphQLNonNull(JobType),
                // TODO: Implement resolver for job
                resolve: () => null,
            },
            dogs: {
                description: 'enter your description',
                type: new GraphQLNonNull(new GraphQLList(GraphQLString)),
                // TODO: Implement resolver for dogs
                resolve: () => null,
            }
        })
    })
})

The only thing the user has to do is hook up the schema to an actual resolve function so that it knows how to query different values. In the future this project may include a CLI utility that can generate a resolve utility that wraps any JSON API.

Try it out

The __tests__ folder currently just contains a small example that you can edit and run. You can change values in api.js and see how the generated schema (which is outputed to the console) changes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].