mongoke
Project description
mongoke
Instantly serve your MongoDb database via graphql
Features
- Powerful Queries: Pagination, filtering, relation, relay-style connections built-in and generated in a bunch of seconds
- Works with existing databases: Point it to an existing MongoDb database to instantly get a ready-to-use GraphQL API
- Authorization via Jwt: Every collection can be protected based on jwt payload and document fields
- Horizontally Scalable: The service is completely stateless and can be replicated on demand
- Apollo Federation: The service can be easily glued with other graphql servers to handle writes and more complicated logic.
- Resilient Idempotent Configuration: One YAML Configuration as the only source of truth, relations, authorization and types in one file
Quickstart:
Docker compose
The fastest way to try Mongoke is via docker-compose.
- Write the configuration to serve a blog database via graphql
# ./mongoke.yml skema: | User: _id: ObjectId username: Str email: Str BlogPost: _id: ObjectId title: Str author_id: ObjectId content: Str types: User: collection: users BlogPost: collection: posts relations: - field: posts from: User to: BlogPost where: author_id: ${{ parent['_id'] }}
- Run the mongoke image with the above configuration via docker-compose up
# docker-compose.yml version: '3' services: mongoke: ports: - 4000:80 image: mongoke/mongoke environment: PYTHONUNBUFFERED: '1' DB_URL: mongodb://mongo:27017/db volumes: - ./mongoke.yml:/conf.yml mongo: image: mongo logging: driver: none
- Query the generated service via graphql or go to
http://localhost:4000
to open graphiql{ user(where: {name: {eq: "jhon"}) { _id name email posts { nodes { title } } } blogPosts(first: 10, after: "Post 1", cursorField: title) { nodes { title content } pageInfo { endCursor hasNextPage } } }
Usage
Mongoke serve your mongodb database via a declarative, idempotent configuration that describes the shape of the types in the database and their relations.
To get started first describe the shape of your types inside the database via the skema language, then write a configuration for every type to connect it to the associated collection and add authorization guards.
Then you can add relations between types, describing what field will lead to the related types and if the relation is of type to_one
or to_many
.
Here is an example:
# example.yml
db_url: mongodb://mongo:27017/db
skema: |
Article:
content: Str
autorId: ObjectId
createdAt: DateTime
User:
_id: ObjectId
name: Str
surname: Str
aricleIds: [ObjectId]
ObjectId: Any
DateTime: Any
types:
User:
collection: users
Article:
collection: articles
relations:
- from: User
to: Article
relation_type: to_many
field: articles
where:
autorId: ${{ parent['_id'] }}
Then generate the server code and serve it with the mongoke docker image
version: '3'
services:
server:
image: mongoke/mongoke:latest
command: /conf.yml
volumes:
- ./example.yml:/conf.yml
mongo:
image: mongo
logging:
driver: none
Then you can query the database from your graphql app as you like
{
author(where: {name: "Joseph"}) {
name
articles {
nodes {
content
}
}
}
}
{
articles(first: 5, after: "22/09/1999", cursorField: createdAt) {
nodes {
content
}
pageInfo {
endCursor
}
}
}
Todo:
publish the docker image (after tartiflette devs fix extend type issue)- resolve issue connection nodes must all have an _id field because it is default cursor field
- integration tests for all the resolver types
- integration tests for the relations
- cursor must be obfuscated in connection, (also after and before are string so it is a must)
add pipelines feature to all resolvers (adding a custom find and find_one made with aggregate)add the $ to the where input fields inside resolvers (in must be $in, ...)remove strip_nones after asserting v1 works
Low priority
required
config field, add verify the jwt with the secret if providedadd schema validation to the configuration- add subscriptions
- add
edges
to make connection type be relay compliant - better performance of connection_resolver removing the $skip and $count
- add a dataloader for single connections
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.