Giter Club home page Giter Club logo

django_graphql_movies's Introduction

Usage

url

https://stackabuse.com/building-a-graphql-api-with-django/

workflow

pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
python manage.py loaddata movies
python manage.py runserver

queries

查询所有actor

query getActors {
  actors {
    id
    name
  }
}

查询单个movie

query getMovie {
  movie(id: 1) {
    id
    title
    actors {
      id
      name
    }
  }
}

mutations

添加actor

mutation createActor {
  createActor(input: {
    name: "Tom Hanks"
  }) {
    ok
    actor {
      id
      name
    }
  }
}

添加movie

mutation createMovie {
  createMovie(input: {
    title: "Cast Away",
    actors: [
      {
        id: 3
      }
    ]
    year: 1999
  }) {
    ok
    movie{
      id
      title
      actors {
        id
        name
      }
      year
    }
  }
}

修改movie

mutation updateMovie {
  updateMovie(id: 2, input: {
    title: "Cast Away",
    actors: [
      {
        id: 3
      }
    ]
    year: 2000
  }) {
    ok
    movie{
      id
      title
      actors {
        id
        name
      }
      year
    }
  }
}

http post request

curl -X POST -H "Content-Type: application/json" --data '{ "query": "{ actors { name } }" }' http://127.0.0.1:8000/graphql/
{"data":{"actors":[{"name":"Michael B. Jordan"},{"name":"Sylvester Stallone"},{"name":"Tom Hanks"}]}}


curl -X POST http://127.0.0.1:8000/graphql/ -H 'Content-Type: application/json' -d '{"query": "{actor(id:1){id name}}"}'
{"data":{"actor":{"id":"1","name":"Michael B. Jordan"}}}

GET方式:http://127.0.0.1:8000/graphql/?query={actor(id:2){id name}}
curl -X GET 'http://127.0.0.1:8000/graphql/?query=%7bactor(id%3a2)%7bid+name%7d%7d'

django_graphql_movies's People

Contributors

florije4ex 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.