DEV Community

Cover image for Plug and Play GraphQL with Django
Mohamad Ashraful Islam
Mohamad Ashraful Islam

Posted on • Updated on

Plug and Play GraphQL with Django

Github (pnp-graphql) v0.0.1-beta

A library for making GraphQL API with Python/Django. This is like a flash drive, just how you plug into computer and transfer files.

What is pnp-graphql?

The tiny library is for making GraphQL in a minute. It considers models based approach. For example, Your app has few models like Book, Author, Publication etc. Now this library will enabled a GraphQL API for all those models. You can do query, mutation on API.

Example Query for "Book"

query getBooks {
  bookList(limit: 500, name: "Honey") {
    id
    name
    publication {
      id
      name
    }
    authors {
      id
      name
      address
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

Example Create Mutation for "Book"

mutation CreateNewBook{
  createbook(input:{
    name: "GraphQL the awesomeness of API development",
    authors: [1,7],
    publication: 103
  }) {
    book{
      id
      name
      authors{
        id
        name
      }
      publication {
        id
        name
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Example Update Mutation for "Book"

mutation updateBook{
  updatebook(id:2, input:{
    name: "Hello Honey Bunny??"
    authors: [1,2,3]
  }) {
    book{
      id
      name
      publication{
        name
      }
      authors {
        id
        name
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Example Delete Mutation for "Book"

mutation deleteBook{
  deletebook(id: 500){
    book
  }
}
Enter fullscreen mode Exit fullscreen mode

Quick Start

Documentation is coming soon...

  • Install from pip pip install pnp-graphql
  • Add PnP GraphQL config on settings.
GRAPHENE = {
    'SCHEMA': 'pnp_graphql.schema.schema'
}

PNP_GRAPHQL = {
    'ENABLED_APPS': ['example_app']
}
Enter fullscreen mode Exit fullscreen mode
  • Set DEBUG = False for production use.

That's it :)

Now visit: http://your-ip:port/api/graphql-explorer/ for explore GraphQL built-in UI explorer for query.

Production ready API : http://your-ip:port/api/graphql/

What's working?

  • GraphQL query
  • Mutation (Create, Update, Delete)
  • Pagination
  • API filtering for Number, String, Date, DateTime

What are the plans?

  • Authentication
  • Proper error handling
  • Field validation
  • Caching
  • many more ... ... ...

Contributors are most welcome :)

Top comments (3)

Collapse
 
fg0ddd profile image
fg0d

!@#$%&*()_

Collapse
 
bimbimprasetyoafif profile image
Bimo Prasetyo Afif

that was simple GraphQl framework that i ever seen, greattt

Collapse
 
ashraful profile image
Mohamad Ashraful Islam

Thank you 😊