GithubHelp home page GithubHelp logo

remorses / mongoke Goto Github PK

View Code? Open in Web Editor NEW
216.0 5.0 12.0 6.58 MB

Home Page: https://mongoke.now.sh/docs/

Python 48.98% Dockerfile 0.28% Shell 0.06% Makefile 0.43% CSS 34.37% HTML 15.89%
graphql mongodb docker generated mongodb-database schema jwt existing-databases cloud docker-compose

mongoke's Introduction

mongoke

Instantly serve your MongoDb database via graphql

Docs โ€ข Examples

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:

Using Docker compose

The fastest way to try Mongoke is via docker-compose.

1. Write the configuration to describe the database schema and relations

The ObjectId scalar is already defined by default, it is converted to string when sent as json

# ./mongoke.yml
schema: |
    type User {
        _id: ObjectId
        username: String
        email: String
    }
    type BlogPost {
        _id: ObjectId
        author_id: ObjectId
        title: String
        content: String
    }

types:
    User:
        collection: users
    BlogPost:
        collection: posts

relations:
    - field: posts
      from: User
      to: BlogPost
      relation_type: to_many
      where:
          author_id: ${{ parent['_id'] }}

2. Run the mongoke image with the above configuration

To start the container mount copy paste the following content in a docker-compose.yml file, then execute docker-compose up.

# docker-compose.yml
version: '3'

services:
    mongoke:
        ports:
            - 4000:80
        image: mongoke/mongoke
        environment:
            DB_URL: mongodb://mongo/db
        volumes:
            - ./mongoke.yml:/conf.yml
    mongo:
        image: mongo

3. Query the generated service via graphql or go to http://localhost:4000/graphiql to open graphiql

{
    User(where: { username: { eq: "Mike" } }) {
        _id
        username
        email
        posts {
            nodes {
                title
            }
        }
    }

    BlogPostNodes(first: 10, after: "Post 1", cursorField: title) {
        nodes {
            title
            content
        }
        pageInfo {
            endCursor
            hasNextPage
        }
    }
}

Tutorials

Check out the /examples directory in this repo

Please help the project making new tutorials and submit a issue to list it here!

mongoke's People

Contributors

bump-version avatar remorses 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  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mongoke's Issues

Does mongoke supports mutations?

Hello @remorses, this project is awesome, very easy set up and deploy. But I have one question, does mongoke supports mutations? I'm planning on creating a database from scratch for insertion and query. Many thanks in advance.

jwt_required is not defined

on examples/authorization

 | INFO:     172.18.0.1:46692 - "POST / HTTP/1.1" 500 Internal Server Error
mongoke_1      | 2020-11-29 09:28:35 httptools_impl ERROR Exception in ASGI application
mongoke_1      | Traceback (most recent call last):
mongoke_1      |   File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
mongoke_1      |     result = await app(self.scope, self.receive, self.send)
mongoke_1      |   File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
mongoke_1      |     return await self.app(scope, receive, send)
mongoke_1      |   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 178, in __call__
mongoke_1      |     raise exc from None
mongoke_1      |   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 156, in __call__
mongoke_1      |     await self.app(scope, receive, _send)
mongoke_1      |   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/base.py", line 25, in __call__
mongoke_1      |     response = await self.dispatch_func(request, self.call_next)
mongoke_1      |   File "./generated/middleware.py", line 26, in dispatch
mongoke_1      |     if jwt_required:
mongoke_1      | NameError: name 'jwt_required' is not defined

[Improvement] Better plurals

This is just an improvement I thought about while demoing on a live stream today. But we had a type called Activity and Mongoke made it Activitys which is a wrong plural, should be "Activities"

Mongoke v2

A new release is on the way, i opened this issue to let people interested in this project share their opinions and ideas

Help me spread the word via twitter if you like the project!

The v2 will add features like

  • Rewrite in Golang
  • No need for Docker
  • Mongoke Cli
  • Mutations Support
  • Auto generate typescript graphql client (via graphql-zeus)

No need for docker

This project aims to make the frontend developers lifes better but usually frontend developers don't know how to use docker, so i decided to make a mongoke cli that starts the server without the need to install docker

Docker has also another problem, images get cached and you won't probably get the last varsion and features for a long time

Mongoke cli

This cli will

  • Validate the configuration
  • Start the generated Mongoke on specified port
  • Mock the data if requested (no need to have a database running)
  • Generate typed graphql client (via graphql-zeus)
  • Watch for changes to the config, reloading the server and regeneratig the js client

Mutations

Mutations will give you a typed database client, this is useful given that mongodb has not a first class schema support, it will prevent many bugs related to inconsistencies to the schema design.
You could use the generated js client in a similar way you use now Prisma.

Generate typescript graphql client

This will be based on the graphql-zeus or graphql-typed-client, let me know what you like more

This is a great time to request new breaking change features requests if you have any

Currently i am rewriting everything in golang to get better performance, using the knowledge already acquired making the python version

`$or` and `$and` operators do not work

Hi there.

It appears the mongo operators are not properly instrumented when they appear inside arrays/lists. For example something like:

{and: [{field1: {eq: val1}},  {field2: {eq: val2}}]}

will not be properly resolved. Specifically, eq will not be transformed to $eq.

The issue seems to be because the code in the template mongoke/templates/resolvers_support.py that does not recurse through lists (only dictionaries). Something like shirouto/mongoke@f88a539 seems to fix it.

Cheers

And operator returns empty query

Hello everyone, I've been trying to query the database using multiple fields, but the data always returns empty. I already made sure the records meets the conditions separately, but when I use the and: operator, I returns empty. I also check the condition in the mongo shell. If anyone can give me a hand with this, I will appreciate it.

This returns records

query {
  TransaccionalNodes(where: {state: {eq: "3"}}){
    nodes {
      _id
      agente_id
      state
    }
  }
}

# result
{
  "data": {
    "TransaccionalNodes": {
      "nodes": [
        {
          "_id": "5edec4e584c4bffa20a64abb",
          "agente_id": "52",
          "state": "3"
        },
        {
          "_id": "5edec3e984c4bffa20a64aba",
          "agente_id": "52",
          "state": "3"
        },
        {
          "_id": "5edec2f484c4bffa20a64ab9",
          "agente_id": "52",
          "state": "3"
        }
      ]
    }
  }
}

This doesn't

query {
  TransaccionalNodes(where: {and: [{state: {eq: "3"}}, {agente_id: {eq: "52"}}]}){
    nodes {
      _id
      agente_id
      state
    }
  }
}

# result
{
  "data": {
    "TransaccionalNodes": {
      "nodes": []
    }
  }
}

Need help with private keys

Hey sir, your app is amazing, but one thing I can't figure yet out.
I have a collection with flags:
-show [true|false]
-deleted [true|false]
-pinned [true|false]

First two of them are private. That mean, I need every graphql request they be equal as show=true AND deleted=false, and I can't expose them.
The third flag is public, so I will expose it and use in queries. Do I need to use pipeline key? I didn't see any examples of usage.

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.