A tool to generate GraphQL schemas from various data sources including JSON files, APIs, and MongoDB collections. The generated schemas can be output as both .graphql
files and Python Graphene classes.
- Generate GraphQL schemas from:
- JSON files
- REST APIs
- MongoDB collections
- Convert schemas to:
.graphql
files- Python Graphene classes
- Support for:
- Nested objects
- Arrays
- Custom types
- Complex data structures
- Clone the repository
git clone https://github.com/FajarWG/graphql-schema-generator.git
- Install dependencies
cd graphql-schema-generator
npm install
Edit the configRest.js file to customize which json or Rest API endpoint will be generated to the graphql schema.
[
{
type: "file",
path: path.join(__dirname, "/dumpJson/input.json"),
typeName: "UserData",
},
{
type: "api",
url: "https://api.example.com/data",
typeName: "ApiData",
},
];
To generate, just do the command:
npm run generate
Configure your MongoDB connection in configDb.js
:
module.exports = {
mongodb: {
uri: "mongodb://localhost:27017",
dbName: "your_database",
collections: ["collection1", "collection2"],
},
};
Generate schema:
npm run generate:db
type UserData {
id: ID!
name: String!
email: String!
age: Int!
}
type NestedData {
items: [ItemType!]!
count: Int!
}
type ItemType {
id: String!
value: Float!
}
import graphene
class UserData(graphene.ObjectType):
id = graphene.ID()
name = graphene.String()
email = graphene.String()
age = graphene.Int()
class ItemType(graphene.ObjectType):
id = graphene.String()
value = graphene.Float()
class NestedData(graphene.ObjectType):
items = graphene.List(ItemType)
count = graphene.Int()
- Node.js >= 14
mongodb
: MongoDB driver for Node.js
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request