GithubHelp home page GithubHelp logo

graphql_server_python_101's Introduction

learn_graphene

https://github.com/graphql-python/graphene

  1. Use example on the above Github page:
  2. Try Flask-GraphQL integration: https://github.com/graphql-python/flask-graphql
  3. Go through query examples https://docs.graphene-python.org/en/latest/quickstart/
    1. setup flask runner for starwars example
    2. play with custom ObjectType, Enums, Interfaces on GraphQL viewer
    3. Mutations:
  4. Adiadne: Schema-first GraphQL

Examples

Error Handling

The query below has a missing argument "todoId":

query {
    todo {
        success
        errors
        todo {
            id
            description
            completed
            dueDate
        }
    }
}

Since it is a bad request, the error thrown in production and debug mode is as follows:

{
  "error": {
    "errors": [
      {
        "locations": [
          {
            "column": 3,
            "line": 13
          }
        ],
        "message": "Field 'todo' argument 'todoId' of type 'ID!' is required, but it was not provided.",
        "path": null
      }
    ]
  }
}

The query below is an intended query to throw an exception:

query {
    todoError(todoId: 1) {
        success
        errors
        todo {
            id
            description
            completed
            dueDate
        }
    }
}

The error thrown in debug mode is as follows:

{
  "data": null,
  "errors": [
    {
      "extensions": {
        "exception": {
          "context": {
            "info": "GraphQLResolv...7feb480e8820>)",
            "obj": "None",
            "todo_id": "'1'"
          },
          "stacktrace": [
            "Traceback (most recent call last):",
            "  File \"/Users/wuhan/Documents/GitHub/graphql/graphql_server_python_101/venv/lib/python3.9/site-packages/graphql/execution/execute.py\", line 617, in resolve_field",
            "    result = resolve_fn(source, info, **args)",
            "  File \"/Users/wuhan/Documents/GitHub/graphql/graphql_server_python_101/venv/lib/python3.9/site-packages/ariadne/utils.py\", line 75, in wrapper",
            "    return func(*args, **convert_to_snake_case(kwargs))",
            "  File \"/Users/wuhan/Documents/GitHub/graphql/graphql_server_python_101/api/queries.py\", line 50, in resolve_todo",
            "    raise Exception('Intended error')",
            "Exception: Intended error"
          ]
        }
      },
      "locations": [
        {
          "column": 3,
          "line": 2
        }
      ],
      "message": "Intended error",
      "path": [
        "todoError"
      ]
    }
  ]
}

The error thrown in production mode is as follows. Compared to the one in debug mode, "extensions" field is missing:

{
  "data": null,
  "errors": [
    {
      "locations": [
        {
          "column": 3,
          "line": 2
        }
      ],
      "message": "Intended error",
      "path": [
        "todoError"
      ]
    }
  ]
}

graphql_server_python_101's People

Contributors

xjohnwu avatar

Watchers

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