Giter Site home page Giter Site logo

django-graphql-demo's Introduction

Documents

Create a services GraphQL Server demo.

Video Guide

GraphQL server lib doc

Install

pip install graphene-django
THIRD_PARTY_APPS = [
    "graphene_django",
]

PROJECT_APPS = [
    'todos_app',
]

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + PROJECT_APPS

############ SETTING UPDATE ###########

GRAPHENE = {
    "SCHEMA": "prod_graphql.schema.my_schema"
}

schema.py

import graphene
from todos_app import schema


class MyQuery(schema.TodoQuery, graphene.ObjectType):
    name=graphene.String(default_value="TungDZ")
    title = graphene.String(default_value="App123")

class MyMutation(schema.TodoMutation, graphene.ObjectType):
    pass


my_schema = graphene.Schema(query=MyQuery, mutation=MyMutation)

Run API

- Demo

{
  name:name
}

{
  name
  title
}
.........
- Get All

{
  todos {
    id
    title
    date
    
  }
}
.........
- Get by ID

{
  todos(id:3) {
    id
    title
    date
    
  }
}
.........
- Create new todo

mutation{
	createTodo(title:"todo 123") {
    todo {
      id
      title
      date
    }
  }  
}

mutation CreateTodo($title:String!){
	createTodo(title:$title) {
    todo {
      id
      title
      date
    }
  }  
}

Query variables
{
    "title": "test variable"
}
.........
- Update Todo by ID

mutation{
	udpateTodo(id:6, title:"todo 6666") {
		todo {
      id
      title
      date
    }
  }  
}

mutation UpdateTodo($id:Int!, $title:String!){
	udpateTodo(id:$id, title:$title) {
		todo {
      id
      title
      date
    }
  }  
}
Query String
{
    "id": 7,
    "title" : "edit todo 7"
}
.........
- Delete Todo by ID:

mutation {
  deleteTodo(id:6) {
      message
    }
}
-----
mutation DeleteTodo($id:Int!){
	deleteTodo(id:$id) {
      message
    }
} 

{
    "id": 7
}

django-graphql-demo's People

Watchers

Tony Tran avatar

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.