-
-
Notifications
You must be signed in to change notification settings - Fork 270
Description
Our applications has user's projects in it; these projects are isolated sets of data. Each project has several tables/collections in it. Projects are created at runtime by the users. The projects start out with a base common schema and set of system fields (id, name, created_at, ..), but part of the application functionality is that users can add/modify/remove user fields as they wish. For example they might add an enum color: [red, blue, green]; that user field would only exist in that user's project. These user defined fields are stored in a table/collection "attribute" in the database for that project (name, type, required, default value...). The users can not modify the system fields.
To implement this, we are using MongoDB and a database-per-project architecture. We have a master database that maps projects to database servers and names. We want to use GraphQL and this package if possible to expose a public API to access and mutate the project data. We have almost everything figured out.. the connection to MongoDB, dynamic database connections and we have this package working great when connecting to a defined database connection (aka project).
What I would like to see is the GraphQL route exposed with a route parameter which identifies the project:
https://api.test.com/project/123/graphql
.. and then Laravel middleware that is responsible for getting the project id, validating and setting the correct database on the connection to MongoDB. All possible.
The question is how can we have dynamic GraphQL schemas and types (per project)? In this package there is a concept of multiple schemas and a default schema, but types are global; so it feels like part of this is there already. However we will have thousands of projects so thousands of schemas and types and they can change at any moment.. so defining them in the config file is out of the question. We have the underlying data to dynamically generate the schema and types from the project's attribute table. The only thing that really changes per project schemas are the type fields and query arguments. Is there a place to intercept or inject into this package when it loads the schema for the current request? These are defined by PHP types, so we would need to be able to also intercepts the call to fields() and args() so they could be modified with the per-project data. If that happens after the project identification middleware, then that would be a place to generate the schema for the current request. We would also like to get graphiql working per project.