Exemplo n.º 1
0
def test_post_request_fails_if_request_content_type_is_not_json(
        schema, request_factory, snapshot):
    view = GraphQLView.as_view(schema=schema)
    request = request_factory.post("/graphql/", content_type="text/plain")
    response = view(request)
    assert response.status_code == 400
    snapshot.assert_match(response.content)
Exemplo n.º 2
0
def execute_query(request_factory, schema, query, **kwargs):
    view = GraphQLView.as_view(schema=schema, **kwargs)
    request = request_factory.post("/graphql/",
                                   data=query,
                                   content_type="application/json")
    response = view(request)
    return json.loads(response.content)
Exemplo n.º 3
0
def test_query_in_valid_post_request_is_executed(schema, request_factory,
                                                 snapshot):
    view = GraphQLView.as_view(schema=schema)
    request = request_factory.post("/graphql/",
                                   data={"query": "{ status }"},
                                   content_type="application/json")
    response = view(request)
    assert response.status_code == 200
    snapshot.assert_match(response.content)
Exemplo n.º 4
0
def test_post_request_fails_if_request_data_is_malformed_json(
        schema, request_factory, snapshot):
    view = GraphQLView.as_view(schema=schema)
    request = request_factory.post("/graphql/",
                                   data="{malformed",
                                   content_type="application/json")
    response = view(request)
    assert response.status_code == 400
    snapshot.assert_match(response.content)
Exemplo n.º 5
0
def test_post_request_fails_for_introspection_when_disabled(
        schema, request_factory, snapshot):
    view = GraphQLView.as_view(schema=schema, introspection=False)
    request = request_factory.post(
        "/graphql/",
        data={"query": "{ __schema { types { name } } }"},
        content_type="application/json",
    )
    response = view(request)
    assert response.status_code == 400
    snapshot.assert_match(response.content)
Exemplo n.º 6
0
def test_playground_html_is_served_on_get_request(request_factory, snapshot):
    view = GraphQLView.as_view()
    response = view(request_factory.get("/graphql/"))
    assert response.status_code == 200
    snapshot.assert_match(response.content)
Exemplo n.º 7
0
def test_playground_options_can_be_set_on_view_init(request_factory, snapshot):
    view = GraphQLView.as_view(playground_options={"test.option": True})
    response = view(request_factory.get("/graphql/"))
    assert response.status_code == 200
    snapshot.assert_match(response.content)
"""server URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

from ariadne.contrib.django.views import GraphQLView
from car.schema import schema

urlpatterns = [
    path('admin/', admin.site.urls),
    path('graphql', GraphQLView.as_view(schema=schema))
]
Exemplo n.º 9
0
]

if settings.DJANGO_GRAPHQL:
    from graphene_django.views import GraphQLView as DjangoGraphQLView

    urlpatterns += [
        path(settings.GRAPHQL_ENDPOINT,
             DjangoGraphQLView.as_view(graphiql=True),
             name='django-graphql')
    ]

if settings.ARIADNE:
    from ariadne.contrib.django.views import GraphQLView as AriadneGraphQLView
    from shop_demo.ariadne.schema import ariadne_schema

    urlpatterns += [
        path(settings.GRAPHQL_ENDPOINT,
             AriadneGraphQLView.as_view(schema=ariadne_schema),
             name='ariadne'),
    ]

if settings.STRAWBERRY:
    from strawberry.contrib.django.views import GraphQLView as StrawberryGraphQLView
    from shop_demo.strawberry.schema import strawberry_schema

    urlpatterns += [
        path(settings.GRAPHQL_ENDPOINT,
             StrawberryGraphQLView.as_view(schema=strawberry_schema),
             name='strawberry'),
    ]
Exemplo n.º 10
0
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
import sys
sys.path.insert(0,'..')
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from ariadne.contrib.django.views import GraphQLView
from gql.schema import schema
from django.views.decorators.csrf import csrf_exempt
from gql.resolvers.context import contextValue

urlpatterns = [
    path('admin/', admin.site.urls),
    #path('graphql/', csrf_exempt(GraphQLView.as_view(schema=schema, context_value=contextValue)),name='graphql'),
    path('graphql/', GraphQLView.as_view(schema=schema, context_value=contextValue),name='graphql'),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
#urlpatterns += static(settings.MEDIA_URL)
Exemplo n.º 11
0
"""products URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""


from django.urls import path
from ariadne.contrib.django.views import GraphQLView
from product.graphql import schema

urlpatterns = [
    path('graphql/', GraphQLView.as_view(schema=schema), name='graphql'),
]
Exemplo n.º 12
0
def view(schema):
    return GraphQLView.as_view(schema=schema)
Exemplo n.º 13
0
from django.contrib import admin
from django.urls import include, path
from django.views.decorators.csrf import csrf_exempt
from ariadne.contrib.django.views import GraphQLView
from api.graphql import resolvers

urlpatterns = [
    path('', include('api.urls')),
    path('admin/', admin.site.urls),
    path('api/', GraphQLView.as_view(schema=resolvers.schema)),
]
Exemplo n.º 14
0
from ariadne import make_executable_schema
from ariadne.contrib.django.scalars import date_scalar, datetime_scalar
from ariadne.contrib.django.views import GraphQLView

from hyakumori_crm.customer.types import types as customers_types
from hyakumori_crm.forest.types import types as forests_types

from hyakumori_crm.customer.resolvers import resolvers as customers_resolvers
from hyakumori_crm.forest.resolvers import resolvers as forest_resolvers, GeojsonDirective

from .types import types as common_types
from .scalars import json_scalar

type_defs = [common_types, customers_types, forests_types]

schema = make_executable_schema(
    type_defs, [
        date_scalar,
        datetime_scalar,
        json_scalar,
        *customers_resolvers,
        *forest_resolvers,
    ],
    directives={"wkt_to_geojson": GeojsonDirective})

view = GraphQLView.as_view(schema=schema, )
Exemplo n.º 15
0
The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from ariadne.contrib.django.views import GraphQLView

from django.contrib import admin
from django.urls import path, include, re_path
from django.views.decorators.csrf import csrf_exempt

from blogsley.django.graphql.schema import schema

urlpatterns = [
    path('', include('blogsley.django.home.urls')),
    path("admin/", admin.site.urls),
    path("graphql/",
         csrf_exempt(GraphQLView.as_view(schema=schema)),
         name="graphql"),
    # This needs to be last
    # path('', include('blogsley.django.sites.urls')),
]
Exemplo n.º 16
0
"""tech_toys URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from ariadne.contrib.django.views import GraphQLView
from api.schema import schema

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', GraphQLView.as_view(schema=schema), name='api'),
    path('', include('main.urls'))
]

admin.site.site_header = "Tech Toys"
admin.site.site_title = "Tech Toys"
admin.site.index_title = "Administration"
Exemplo n.º 17
0
from django.contrib import admin
from django.urls import path
from ariadne.contrib.django.views import GraphQLView

from base.graphql.global_schema import schema

urlpatterns = [
    path("admin/", admin.site.urls),
    path("graphql/", GraphQLView.as_view(schema=schema), name="graphql"),
]
Exemplo n.º 18
0
 def register_urlpatterns(self, urlpatterns):
     # GraphQL API
     urlpatterns.namespace(r"^graphql/", "graphql")
     urlpatterns.patterns(
         "graphql",
         url(r"^$", GraphQLView.as_view(schema=schema), name="index"))
Exemplo n.º 19
0
from ariadne import load_schema_from_path
from ariadne.contrib.django.views import GraphQLView
from ariadne.contrib.federation import make_federated_schema

from parking_permits import admin_resolvers, resolvers
from parking_permits.error_formatter import error_formatter
from project.settings import BASE_DIR

type_defs = load_schema_from_path(BASE_DIR / "parking_permits" / "schema" /
                                  "parking_permit.graphql")
schema = make_federated_schema(type_defs, resolvers.schema_bindables)
view = GraphQLView.as_view(schema=schema, error_formatter=error_formatter)

admin_type_defs = load_schema_from_path(
    BASE_DIR / "parking_permits" / "schema" / "parking_permit_admin.graphql")
schema = make_federated_schema(admin_type_defs,
                               admin_resolvers.schema_bindables)
admin_view = GraphQLView.as_view(schema=schema,
                                 error_formatter=error_formatter)
Exemplo n.º 20
0
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from .schema import schema
from django.urls import path
from neo4j import GraphDatabase
from django.contrib import admin
from ariadne.contrib.django.views import GraphQLView

driver = None


def context(request):
    global driver
    if driver is None:
        driver = GraphDatabase.driver("bolt://localhost:7687",
                                      auth=("neo4j", "neo4j123"))

    return {'driver': driver, 'request': request}


urlpatterns = [
    path('admin/', admin.site.urls),
    path('graphql/',
         GraphQLView.as_view(schema=schema, context_value=context),
         name='graphql'),
]