저는 GraphQL API를 빌드 할 때 graphen-django를 사용합니다. 이 API를 성공적으로 만들었지 만 응답을 필터링하기위한 인수를 전달할 수 없습니다.graphene-django - 필터링 방법?
이 내 models.py입니다 : 이것은 내 schema.py
from django.db import models
class Application(models.Model):
name = models.CharField("nom", unique=True, max_length=255)
sonarQube_URL = models.CharField("Url SonarQube", max_length=255, blank=True, null=True)
def __unicode__(self):
return self.name
입니다 : 모델에서 graphene_django 수입 DjangoObjectType 에서 수입 그래 핀 가져올 응용 프로그램
class Applications(DjangoObjectType):
class Meta:
model = Application
class Query(graphene.ObjectType):
applications = graphene.List(Applications)
@graphene.resolve_only_args
def resolve_applications(self):
return Application.objects.all()
schema = graphene.Schema(query=Query)
내 urls.py :
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^admin/', admin.site.urls),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api-token-auth/', authviews.obtain_auth_token),
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
]
자세히 알 수 있듯이 REST API도 있습니다.
내 settings.py이 포함
GRAPHENE = {
'SCHEMA': 'tibco.schema.schema'
}
나는이를 수행 https://github.com/graphql-python/graphene-django
나는이 resquest 보낼 때 :이 응답을 가지고
{
applications {
name
}
}
을 :
{
"data": {
"applications": [
{
"name": "foo"
},
{
"name": "bar"
}
]
}
}
그래서 작동합니다!
하지만이 같은 인수를 전달하려고하면 내가{
"errors": [
{
"message": "Unknown argument \"name\" on field \"applications\" of type \"Query\".",
"locations": [
{
"column": 16,
"line": 2
}
]
}
]
}
을 놓친 무엇 :
{
applications(name: "foo") {
name
id
}
}
을 나는이 반응을? 아니면 내가 뭔가 잘못한거야? 이것은 내 대답이다 http://docs.graphene-python.org/projects/django/en/latest/tutorial.html
: