Created
November 4, 2019 16:54
-
-
Save zer0tonin/79344ddc8e6fa286f5b325e283073d16 to your computer and use it in GitHub Desktop.
tartiflette-plugin-scalars example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | |
) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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