GithubHelp home page GithubHelp logo

Comments (6)

lucasconstantino avatar lucasconstantino commented on April 30, 2024 2

Here is a small project I've being working on https://github.com/lucasconstantino/graphql-modules/

from graphql-tools.

tomitrescak avatar tomitrescak commented on April 30, 2024 1

Hi, I created a package that allows for modular definition of graphql schemas. It can be found here. Would be great if something like this would be in the core ;)

https://www.npmjs.com/package/apollo-modules

from graphql-tools.

helfer avatar helfer commented on April 30, 2024

@tomitrescak your package looks interesting, but I'm a bit confused because it seems to do more than just let you create a schema in a modular way. For example, there's also a function to create input types from output types, and a function to modify options based on the request.

I think it would be best if modular schema creation was limited to just the schema itself, and allowed you to start with a base schema and then extend that with modules. Unfortunately that would require modifications to graphql-js or monkey patching a schema. If I were to implement it, I think I would just try monkey patching an existing schema, but that could be rather tedious programming work and is probably pretty error-prone.

from graphql-tools.

gadicc avatar gadicc commented on April 30, 2024

I'm also very interested in this, relating back to apollographql/apollo#28. It's currently a lot of work for devs to add "apollo packages" (packages that include their own schema). I know it's possible to gradually construct the typeDefs via imported arrays, but there's no way to add root queries and mutations.

I was going to propose the following API:

const es = makeExecutableSchema(...);

es.addType(name, definition);
es.addRootQuery(name, definition);
es.addRootMutation(name, definition);
es.remove*(name, definition);

This is break from the common way of setting up everything in advance, and instead does a lot at "runtime", making it more efficient for HMR and potentially allowing for "runtime packages" (that are installed in a running app).

But if I understood correctly, the proposal here is much better. However, @tomitrescak, I couldn't quite understand from the README what it would look like. Any chance of an example somewhere of how both an app, and package, would use this with each other?

from graphql-tools.

tomitrescak avatar tomitrescak commented on April 30, 2024

@gadicc I have recently updated the documentation.

My "solution" thinks a lot about importing modules from the packages.
All you need to do is import all modules from the package when you are constructing your schema:

import { addModules } from 'apollo-modules';
import { makeExecutableSchema } from 'graphql-tools';
import { modules } from 'my-package'; 

const modules = addModules(modules);

// build your schema 
const schema = makeExecutableSchema({ typeDefs: modules.schema, resolvers: modules.resolvers);

Using the below definition of modules, you can even specify how given module changes context on each request in modifyOptions function:

interface ApolloModule {
  // definition of types 
  schema: string;
  // definition of queries
  queryText?: string;
  // implementation of queries
  queries?: Object;
  // implementation of type resolvers
  resolvers?: Object;
  // definition of mutations
  mutationText?: string;
  // implmentation of mutations
  mutations?: Object;
  // allows you to modify apollo Options (e.g. context) based on current request
  modifyOptions?: (req: any, apolloOptions: ApolloOptions) => void 
}

The REAL downside of this approach is that this would have to become a "standard" as you need to construct your whole schema using apollo-modules and you cannot combine approaches.

from graphql-tools.

stubailo avatar stubailo commented on April 30, 2024

This is a great solution, for now we have these directions as well: http://dev.apollodata.com/tools/graphql-tools/generate-schema.html#modularizing

I think adding the following specific feature will resolve the rest of the needs for which one would currently need apollo-modules: #182

But I'm excited about continued innovation in schema development!

from graphql-tools.

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.