petr-korobeinikov / graphql-python-showcase

Stop using REST, Post-JSON, and other stuff from 2k00.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

graphql-python-showcase

Stop using REST, Post-JSON, and other stuff from 2k00.

Running the project

DOCKER_BUILDKIT=1 docker build -t graphql-python-showcase .
docker run --rm -p 9000:9000 graphql-python-showcase

Open http://<your-docker-host>:9000/.

graphiql

Running queries

Find all projects

query allProjects {
    projects {
        id
        name
        slug
    }
}

Find all project names

query allProjectNames {
    projects {
        name
    }
}

Find all project with tasks

query allProjectsWithTasks {
    projects {
        id
        name
        tasks {
            id
            title
        }
    }
}

Find project by slug (query variable demo)

query projectBySlug($slug: String!) {
    projectBySlug(slug: $slug) {
        id
        name
        slug
    }
}

Provide a required slug variable:

{
    "slug": "proj1"
}

Using directive example

query projectWithTasksBySlug($slug: String!, $withTasks: Boolean!) {
    projectBySlug(slug: $slug) {
        id
        name
        slug
        tasks @include(if: $withTasks) {
            id
            title
        }
    }
}
{
    "slug": "proj1",
    "withTasks": true
}

Find assignees

query projectBySlug($slug: String!) {
    projectBySlug(slug: $slug) {
        id
        name
        slug
        tasks {
            id
            title
            assignee {
                id
                name
            }
        }
    }
}

Type introspection

query projectBySlugIntrospected($slug: String!) {
    projectBySlug(slug: $slug) {
        __typename
        id
        name
        slug
        tasks {
            __typename
            id
            title
            assignee {
                __typename
                id
                name
            }
        }
    }
}

Running mutations

Create a project

todo: use variables

mutation createProject {
    createProject(name: "Project 4", slug: "prj4") {
        project {
            id
            name
            slug
        }
        ok
    }
}

Reassign a task

todo: use variables

mutation reassignTask {
    reassignTask(taskId: 1, assigneeId: 2) {
        task {
            id
            assignee {
                id
                name
            }
        }
        ok
    }
}

TODO

Add:

  • Enums (task status)
  • Pagination
  • Fragments
  • Auth

Python + GraphQL quick start

Main GraphQL learning resource

Free learning resources

Paid learning resources

About

Stop using REST, Post-JSON, and other stuff from 2k00.


Languages

Language:Python 94.6%Language:Dockerfile 5.4%