Skip to content

Instantly share code, notes, and snippets.

@zer0tonin
Created November 4, 2019 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zer0tonin/79344ddc8e6fa286f5b325e283073d16 to your computer and use it in GitHub Desktop.
Save zer0tonin/79344ddc8e6fa286f5b325e283073d16 to your computer and use it in GitHub Desktop.
tartiflette-plugin-scalars example
import asyncio
from ipaddress import ip_address
from tartiflette import Resolver, create_engine
from aiohttp import web
from tartiflette_aiohttp import register_graphql_handlers
@Resolver("Query.ipAddress")
async def resolve_ip_address(parent, args, ctx, info):
return ip_address("127.0.0.1")
@Resolver("Query.port")
async def resolve_port(parent, args, ctx, info):
return 8080
@Resolver("Mutation.checkGUID")
async def resolve_guid(parent, args, ctx, info):
return args["input"]
async def engine():
with open("schema.sdl") as schema:
return await create_engine(
schema.read(),
modules=[
{
"name": "tartiflette_plugin_scalars",
"config": {},
}
],
)
web.run_app(
register_graphql_handlers(
web.Application(),
engine=engine(),
)
)
type Query {
ipAddress: IPv4
port: Port
}
type Mutation {
checkGUID(input: GUID!): GUID!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment