Generate GraphQL schema from data in MongoDB collection.
npm install m2gql --save-dev
m2gql -d DB_PATH -m NAME -c COLLECTION -f ./location/file.graphql -s COMPANY
- Path to Database
- This field is mandatory
- Specify single collection ( otherwise it will generate types from all collections in db )
- If fetched one collection, provide name of Type
- Default value is collection name
- File location on which to save GraphQL Types
- Name to write in schemas collection of Database
File path or company name must be provided
Function which create GraphQL types out of data provided
createGraphQL(collections)
Function return formatted string of GraphQL Types
createGraphQL(
{
user: [
{
first_name: "John",
last_name: "Doe"
},
{
first_name: "Mike",
last_name: "Smith"
}
]
}
)
- Array of collections
[
{
collectionName: [CollectionData]
},
{
collectionName2: [CollectionData2]
},
]
- Single collection
{
collectionName: [CollectionData]
}
Creating GraphQL Types from Database provided
createFromDB(databaseURI, collectionName, modelName, companyName)
createFromDB('mongodb://localhost:25555/PinterestDB', 'users')
- Path to Database in which to search for elements.
- This field is mandatory
- If wanted Graphql Type of just one collection
- If fetched one collection, provide name of Type
- Default value is collection name
- Company name to write in schemas collection of Database