I use graphen-django for build a GraphQL API. I have succesfully create this API, but I can't pass a argument for filter my response.
This is my models.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
This is my schema.py: import graphene from graphene_django import DjangoObjectType from models import Application
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)
My 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)),
]
As you can see, I also have a REST API.
My settings.py contains this:
GRAPHENE = {
'SCHEMA': 'tibco.schema.schema'
}
I follow this: https://github.com/graphql-python/graphene-django
When I send this resquest:
{
applications {
name
}
}
I've got this response:
{
"data": {
"applications": [
{
"name": "foo"
},
{
"name": "bar"
}
]
}
}
So, it's works!
But when I try to pass an argument like this:
{
applications(name: "foo") {
name
id
}
}
I have this response:
{
"errors": [
{
"message": "Unknown argument \"name\" on field \"applications\" of type \"Query\".",
"locations": [
{
"column": 16,
"line": 2
}
]
}
]
}
What i have missed? Or maybe I do something wrong?
DjangoListField
– Meyerbeer