Skip to content

emka.web.id

Menu
  • Home
  • Indeks Artikel
  • Tutorial
  • Tentang Kami
Menu

How to Use GraphQL with Python

Posted on November 04, 2020 by Syauqi Wiryahasana
In this tutorial, we will try to use the GraphQL library in python, Strawberry GraphQL. Python GraphQL library based on dataclasses. to install Strawberry GraphQL: pip install strawberry-graphql Example sourcecode: [sourcecode language="python"] import strawberry @strawberry.type class User: name: str age: int @strawberry.type class Query: @strawberry.field def user(self, info) -> User: return User(name="emka", age=20) schema = strawberry.Schema(query=Query) [/sourcecode] This will create a GraphQL schema defining a User type and a single query field user that will return a hardcoded user. To run the debug server run the following command: strawberry server app Open the debug server by clicking on the following link: http://0.0.0.0:8000/graphql This will open GraphiQL where you can test the API.
Seedbacklink

Recent Posts

TENTANG EMKA.WEB>ID

EMKA.WEB.ID adalah blog seputar teknologi informasi, edukasi dan ke-NU-an yang hadir sejak tahun 2011. Kontak: kontak@emka.web.id.

©2024 emka.web.id Proudly powered by wpStatically