Giter Site home page Giter Site logo

Comments (3)

phryneas avatar phryneas commented on May 17, 2024 2

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.

kettanaito avatar kettanaito commented on May 17, 2024 1

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.

kettanaito avatar kettanaito commented on May 17, 2024 1

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.