Comments (3)
I don't really have the time for that as I have tons of open issues to work on myself :/
But if I find one or two hours I'll dig into the code - maybe it's less work than I'm imagining.
But otherwise, if someone else sees this issue and thinks "Hey, I can do this" - take it! :D
I don't really need this right now (although it would be nice in our examples), I just noticed it and wanted to put it here as a suggestion for the roadmap - with whichever priority you give it in the end :)
from data.
Hey, @phryneas. You're right, the current GraphQL type of a relation would be reduced to a primitive, which doesn't produce a valid GraphQL schema in the end:
factory({
user: {
post: oneOf('post')
},
post: { ... }
})
type User {
- post: String
+ post: Post
}
I can't say from the top of my head if the schema generation logic can determine a value being a relational node to infer its type, or we'd have to extend the logic to have access to relational nodes.
Please, would you be interested in tackling this? I'd be happy to help with code reviews in the process.
from data.
Since a model may reference other models (relational properties), it's no longer possible to generate a complete GraphQL schema from a single given model (it may depend on other models).
In other words, given a factory like this:
const db = factory({
user: {
id: primaryKey(datatype.uuid),
role: oneOf('role'),
},
role: {
id: primaryKey(datatype.uuid),
name: String,
},
})
Generating the GraphQL types via db.user.toGraphQLSchema()
become a no-op in the current implementation, as in order to type the role
field of the User
type the library needs to generate the Role
type of an unrelated model definition.
As I've suggested above, it looks like the library needs to have access to the entire dictionary to generate a complete GraphQL schema for any given model. At first, I thought about optimizing the generation process by analyzing model dependencies a single dependency has (what models it references, like user
above references the role
model), but I came to realize that'd be a bad idea. Models may depend on other models, and now we're compiling a model dependency tree and it's likely to be a mess that results in the entire dictionary being converted into a GraphQL schema anyway.
To summarize, it looks like this change implies the internal change:
-generateGraphQLSchema(model): GraphQLSchema
# We'd have to expose the dictionary and generate GraphQL types for all models.
+generateGraphQLSchema(model, dictionary): GraphQLSchema
from data.
Related Issues (20)
- Can we store a literal object to an entity's field? HOT 8
- Using zod to generate table schema
- comparator missing for find by id
- Using wildcard/parameters in baseUrl in toHandlers method HOT 4
- Required oneOf relation HOT 6
- Poor performance when creating linked entities
- Database ID is not unique when extracted to a setup helper file (using Vitest) HOT 4
- Help Creating Type-Safe Models HOT 2
- Support transient attributes HOT 5
- Library's state and future HOT 13
- manyOf relationship in nullable objects HOT 1
- pnpm resolves msw optional dependency as v2 instead of v1 HOT 4
- Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'get') while generating handlers HOT 1
- Add toHandlers('json-api') support
- REST toHandlers() PUT and POST do not work with @mswjs/http-middleware due to req.body being a string
- Add the ability to set a foreign key on a model to create relationships HOT 1
- Make MSW/Data more type compatible with FakerJS functions HOT 1
- Typing issue when returning relation properties
- Faker definition for relationship properties
- Factory model for a Union Type model HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data.