コード例 #1
0
def make_app(db: AsyncIOMotorClient = None):
    try:
        if not db:
            db = AsyncIOMotorClient(DB_URL).get_database()
        graphiql = GraphiQL(
            # path=MONGOKE_BASE_PATH,
            default_headers={
                "Authorization": "Bearer " + GRAPHIQL_DEFAULT_JWT
            } if GRAPHIQL_DEFAULT_JWT else {},
            default_query=GRAPHIQL_QUERY,
        )

        context = {"db": db, "loop": None}

        app = TartifletteApp(
            context=context,
            engine=engine,
            path=MONGOKE_BASE_PATH,
            graphiql=graphiql if not DISABLE_GRAPHIQL else False,
        )
        app = CORSMiddleware(
            app,
            allow_origins=["*"],
            allow_methods=["*"],
            allow_headers=["*"],
        )
        app = JwtMiddleware(app, )
        # app = CatchAll(app,)
        app = ServerErrorMiddleware(app, )
        return app
    except Exception as e:
        print('got an error starting the Mongoke server:')
        print(e)
        return
コード例 #2
0
def test_defaults(engine: Engine, variables: dict, query: str, headers: dict):
    graphiql = GraphiQL(default_variables=variables,
                        default_query=query,
                        default_headers=headers)
    ttftt = TartifletteApp(engine=engine, graphiql=graphiql)

    with build_graphiql_client(ttftt) as client:
        response = client.get("/")

    assert response.status_code == 200
    assert json.dumps(variables) in response.text
    assert inspect.cleandoc(query) in response.text
    assert json.dumps(headers) in response.text
コード例 #3
0
async def test_defaults(engine: Engine, variables: dict, query: str,
                        headers: dict) -> None:
    graphiql = GraphiQL(default_variables=variables,
                        default_query=query,
                        default_headers=headers)
    app = TartifletteApp(engine=engine, graphiql=graphiql)

    async with get_client(app) as client:
        response = await client.get("/", headers={"accept": "text/html"})

    assert response.status_code == 200
    assert json.dumps(variables) in response.text
    assert inspect.cleandoc(query) in response.text
    assert json.dumps(headers) in response.text
コード例 #4
0
import inspect
import json
import re
import typing

import pytest
from starlette.applications import Starlette
from starlette.testclient import TestClient
from tartiflette import Engine

from tartiflette_asgi import GraphiQL, TartifletteApp, mount


@pytest.fixture(name="graphiql",
                params=[False, True,
                        GraphiQL(),
                        GraphiQL(path="/graphql")])
def fixture_graphiql(request: typing.Any) -> typing.Union[GraphiQL, bool]:
    return request.param


def build_graphiql_client(ttftt: TartifletteApp) -> TestClient:
    client = TestClient(ttftt)
    client.headers.update({"accept": "text/html"})
    return client


@pytest.fixture(name="client")
def fixture_client(graphiql: typing.Any,
                   engine: Engine) -> typing.Iterator[TestClient]:
    ttftt = TartifletteApp(engine=engine, graphiql=graphiql)
コード例 #5
0
ファイル: main.py プロジェクト: remorses/tartiflette-wheels
import os
from tartiflette import Resolver, Engine
from tartiflette_asgi import TartifletteApp, GraphiQL
from tartiflette_plugin_apollo_federation import ApolloFederationPlugin
from .support import read

DISABLE_GRAPHIQL = bool(os.getenv("DISABLE_GRAPHIQL", False))
GRAPHIQL_DEFAULT_JWT = os.getenv("GRAPHIQL_DEFAULT_JWT", "")
GRAPHIQL_QUERY = os.getenv("GRAPHIQL_DEFAULT_QUERY", "") or read(
    os.getenv("GRAPHIQL_DEFAULT_QUERY_FILE_PATH", ""))

graphiql = GraphiQL(
    path="/",
    default_headers={"Authorization": "Bearer " +
                     GRAPHIQL_DEFAULT_JWT} if GRAPHIQL_DEFAULT_JWT else {},
    default_query=GRAPHIQL_QUERY,
)


@Resolver("Query.hello")
async def hello(parent, args, context, info):
    name = args["name"]
    return f"Hello, {name}!"


sdl = """
type Query { 
    hello(name: String): String
}
"""