Does graphene-django dynamically create an API documentation? - django

I'm considering using GraphQL with a Django backend service but I couldn't find much information regarding the API documentation. I need some solution to dynamically generate the documentation, perhaps like npm's graphql-docs with a result similar to GitHub's API docs.
Is it feasible to accomplish with graphene-django? If not, what's a good alternative for a python environment?

Yes, it's very easy to do by using GraphiQL, which is embedded in to Graphene.
The instructions on how to integrate this with Graphene are here in the graphene-python documentation. --- basically you need to add the parameter graphiql=True when setting up the API route in your urls.py file.
After it is set up, if go to your API endpoint in your browser, you'll see a nice interface for sending API calls, getting API responses, and reading documentation for both queries and mutations. The documentation is initially hidden on the right until you click on the "< Docs" link.

Related

CLI/SDK to create Google-cloud oAuth client

Is it possible to create an OAuth client (https://developers.google.com/identity/protocols/OAuth2) using a script (gcloud or any library)?
Google recommended way (https://developers.google.com/identity/protocols/OAuth2WebServer#creatingcred) is to manually create from https://console.developers.google.com/apis/credentials.
I have multiple apps with different url_redirects like https://a.domain.com, https://b.domain.com https://c.domain.com, https://d.domain.com, this subdomain list is large to manage manually.
I want to automate this process for my use case. I'm not able to find any library to do this.
Update: Endpoint used by GCP console https://clientauthconfig.clients6.google.com/v1/clients and there is related permission also "clientauthconfig.clients.create" but there is no API provided for it.
You would need API client to create new API client anyway. Is it really necessary for you to create it this way? You can rather create multiple "user" credentials for your application using only that one API client.
I think you are looking for something like this, hope Java is good for you.
I've also found the following relevant information that might help you. Link
Also relevant for you. Link
Let me know.

Django Swagger and JSON API render issues

Using django-rest-framework-json-api I am able to create API end points that work as described within the documentation. Attempted to provide API documentation using django-rest-swagger is not so easy.
1: Swagger uses media_type = 'application/json' which is not supported in the JSON API. To get around this I created a second render class (renderer_classes) that sub classes the JSON API JSONRenderer and forces the media type.
Now the end point supports application/json and application/vnd.api+json and swagger is happy to render in JSON API document structure. Aware that the generated curl requests have none a standard JSON API header.
2: Swagger has the same issue with the parser. While the work out from issue 1 does work there is a secondary challenge. Swagger renders a flat dictionary of field names which is not JSON API and ultimately is requested by DRF.
Is it possible to get swagger to parse in JSON API? At the moment Swagger is not working for PUT or POST.
djangorestframework-jsonapi==2.2.0
djangorestframework==3.5.4
Django==1.11.2
coreapi==2.3.1
python 3.6
Answering my own question here so that others can gain value from what was learnt. We never found a solution to this issue and we did not have the time available to contribute to this project. In general the project also appears to be struggling, maybe due to people like us not contributing...
An alternative project drf-yasg has now emerged, which did not exist at the time of this original posting. drf-yasg was relatively easy to deploy and solved all of our issues so we have now migrated to this project instead.
So if you a looking for swagger api documentation for JSON API endpoints created within DRF, then I would suggest drf-yasg.
At the time of writing JSON API is not supported out of the box, but there is sample code to get it up and running relatively easily. With this change in place, all of the endpoints will be auto documented.
This Github Gist that contains the code from our app, hope that this helps you out until this feature is fully developed.
As you pointed out in your own answer there is an alternative: drf-yasg. This is great package but does not support JSON API schema out of the box.
That's way you'd even better use drf-yasg-json-api that adds JSON API support to drf-yasg by providing all necessary field inspectors, you just need to slightly extend your SWAGGER_SETTINGS.
Check drf-yasg-json-api Github repo for details.
Disclaimer: I am the author of this package.

Advantages of using REST API framework over simple URL and view creation in Django?

It might be a silly question for many, but why can't I instead
Create a view in django that takes a request and returns HttpResponse in, say, JSON format
Map the view to a URL
Hit the URL from my browser or another server and use the result?
Thanks.
EDIT - Two approaches: Import some djangorestframework or tastypie and build an api in my application which will throw json responses VS building a view and tell it to return json response. Is there any huge advantage of using the first one?
I think you could make the same argument about any extension library. It just depends on how much you want to rebuild and what the existing library has that would be beneficial to your project.
Many times I've created custom endpoints without an API library when working with ajax requests inside my project. For that instance, using an API package is overkill. But for having a full API server, Django rest framework offers a lot of functionality.
Sure, you can make views that do what you suggested. But at some point are you going to want to authenticate through an HTTP request? Are you going to want to filter? Are you going to want to make permissions, or just have all endpoints open? Are you going to want to protect against CORS?
You can kind of go down the list of all the features of an API library and ask these questions about what you want to accomplish with your project. If you're working with any type of external application and your django project is just for an API server, usually it's best to go with Rest Framework. If you just have some one-off endpoints to receive ajax requests, usually you just want to build custom endpoints.

Migration path for Fql.multiquery

I'm new to Facebook development. I'm working on migrating an existing app in accordance to the Graph API upgrade guide. I'm looking for guidance around calls such as api.facebook.com/method/Fql.multiquery.
My question is: does this type of API need to be upgraded as well, or does it only apply to graph.facebook.com calls? I want to ensure that api.facebook.com/method/Fql.multiquery calls will still work after 4/30/15.
You may want to take a look at the Batch Requests of the Graph API. You can also specify dependencies between the requests.
Calls to http://api.facebook.com/method/Fql.multiquery will no longer work. The REST API is long deprecated anyway.
As #luschn said, you have to migrate to the Graph APIs batch requests, and use the /fql endpoint. You can only use FQL if you have a v2.0 app, and not higher.

Browser plugin to import REST Web Services WADL file and provide invocation page

Looking for a Browser plugin that can parse a REST Web Services wadl file and present a page listing all the services and a way to invoke any of the services setting appropriate parameters.
Try Timboo.com They have about 2,000 different entries for various API Methods as "choreos" for choreographies, and you might find yours already there or you could import your defs into their system. Even DreamFactory.com or apigee.com have similar features. Which service are you interested in? Even Cloud9.com can support most of what you need. Or Node.js or Modulus.com Good luck.