How to use selectionSet in graphql field resolver - apollo

I'm writing code that needs to use the extend schema.
But I can't use stitch because I'm using federation.
So I am implementing a field resolver with one local graphql schema, but I want the server to add the fields needed by the field resolver.
How can I do this?

Related

Rest API instead of table in Django Proxy unmanaged models

In my Django arch. task I must connect multiple projects. Some can only communicate through REST API and don't have common database access. However, the task is to provide seamless communication on model level. I.e. my model should serve as a wrapper for read-only requests in such a way, that business layer does not see the difference between local models and models that wrap remote data. Assuming that inherited create-delete-update methods will do nothing and network communication and authentication is handled by some method:
read_remote_records(**kwargs)
This method returns any data that I would need for my model. All I need is to wrap it in query set api for seamless use in views.
I have read these:
Proxy models documentation
Unmanaged models documentation
Also documentation on creation of custom managers and querysets.
However, not a single good example for what I am set to achieve.
Perhaps you can provide a solid Django example how to modify manager and query set in this way?

Do I have to use Django Models to use the API?

We are migrating our intranet application and have decided to choose the Django framework. We control all of our database via source control and managed scripts, so we do not use the migrate feature to create tables for us. Views and Tables can change, all business logic is held in the database.
I want to make Django API endpoint which is basically select * from my_table_or_view; and Django can return a JSON response with the column names and values. Some database tables have close to 100 columns each so I don't want to write out each and every field name and type just to return a query. What happens if we add another column to the view - will I have to update it in Django as well? What if I change the column type - will my application fail as well?
The frontend is written in VueJS - it makes a request to the API endpoint and should use the columns selected in the frontend, obviously if I remove a column it will break but I don't want to have to add the column in the django framework even if it is not used.
I've read the raw SQL queries section of the docs but i'm not sure where this applies to. Does this logic sit in the views section?
I've tried directing a URL endpoint in URLS.py to a custom class in views.py but not sure this is correct, does this logic need to be in a serializer?
I'd like the simplest method possible, potentially not using models, just raw SQL is fine.
One option for you is to sync your db to django models every time you change your schema and then use it normally, both ORM and raw SQL queries would be possible.
There's a function called inspectdb that does that natively, here is a reference to it
https://docs.djangoproject.com/en/3.1/ref/django-admin/#inspectdb

How to store json from request directly into mongo database

I would like to store json from request body directly into mongo collection without creation of specific model in django. I cannot create it because specific fields in json may change and new ones can be introduced, so I would like rather to store it as it is without this abstraction layer. Is it possible?

How to make Tastypie reject unrecognized input data

I am currently using Tastypie to provide a programmatic interface to my Django database. On problem that I've run into a couple of times is that when client code uploads data for a field that doesn't exist, Tastypie ignores it. This means that the client code has no idea that some of the data that it tried to upload was ignored. I'd like to tell the client that it tried to upload an unknown field, possible with a status code 406 (not acceptable).
I have two related questions:
Is it appropriate for RESTful design to reject this extra data?
If so, is there a tidy way to do this through Tastypie?
As an example of my concern, consider this toy Tastypie API:
from tastypie import resources, fields
class DemoResource(resources.ModelResource):
name = fields.CharField()
optional = fields.CharField(blank=True)
If client code uploaded the json data: {name: "new data", optioanl: "this field is misspelled"}, the misspelled optional field would be ignored. My current plan is to use a Tastypie validator to compare the bundle data against the bundle object, but this seems really non-DRY.

Add endpoints to top level schema in tastypie

I have a django-tastypie project, where I've added nested resources to the schema. I'd like to add these endpoints to the top level schema, generated in api.top_level, but I don't see an easy way of doing this without re-writing the top_level method and hard coding the new endpoints.
Is there an easy way of adding nested resources to the top level schema, or is there a better way of doing this.
E.g. adding list-endpoint and schema fields for each nested endpoint in the parent schema.