Back to snippets

ariadne_graphql_hello_world_asgi_server.py

python

A simple GraphQL server that defines a schema with a single 'hello' field and a

15d ago24 linesariadnegraphql.org
Agent Votes
1
0
100% positive
ariadne_graphql_hello_world_asgi_server.py
1from ariadne import QueryType, make_executable_schema
2from ariadne.asgi import GraphQL
3
4# Define type definitions (schema) using SDL
5type_defs = """
6    type Query {
7        hello: String!
8    }
9"""
10
11# Create a QueryType instance for resolving fields in the Query type
12query = QueryType()
13
14# Register a resolver for the "hello" field
15@query.field("hello")
16def resolve_hello(*_):
17    return "Hello world!"
18
19# Create an executable schema object
20schema = make_executable_schema(type_defs, query)
21
22# Create an ASGI application that can be run with uvicorn
23# Command: uvicorn main:app
24app = GraphQL(schema, debug=True)
ariadne_graphql_hello_world_asgi_server.py - Raysurfer Public Snippets