Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

resolvers management #29

Closed
abhiaiyer91 opened this issue Apr 24, 2016 · 5 comments
Closed

resolvers management #29

abhiaiyer91 opened this issue Apr 24, 2016 · 5 comments

Comments

@abhiaiyer91
Copy link

abhiaiyer91 commented Apr 24, 2016

I was wondering if you guys were thinking about how resolvers will be managed as the Namespaces grow in number and in size?

I was thinking you could do something like...

function generateRootQuery(Query) {
 return {
    Query
  };
}

function author(root, args){
      return Authors.findOne({
        firstName: args.firstName,
        lastName: args.lastName
      }, {
        fields: {
          'firstName': 1,
          'lastName': 1
        }
      });
    }
}

export const rootQuery = generateRootQuery({ author });

This would work well becuse you could then separate the query resolvers into modules, then do a rootQuery export.

Then you could combine resolvers as well

function rootResolver(Query, Types) {
   return Object.assign({}, {Query}, {...Types});
}


// used like

import rootQuery from '/imports/data/rootQuery';
import Author from '/imports/data/resolvers/Author';

export default rootResolver(rootQuery, {Author});

I dont know something like that?

@helfer
Copy link

helfer commented Apr 24, 2016

Composing resolve functions is a great idea! Sashko and I have been toying with the idea a little bit, but I haven't implemented anything for it.

Composing resolvers in the way you propose is actually already possible right now, so I think it would just be a matter of making an 'official' recommendation of how people should do it.

Just one question: I don't really see any namespacing in your examples. Maybe we could add that with a simple function where you can give both the field and the resolve function a prefix or something?

Ideally, we'd like to be able to compose both type definitions and resolve functions, such that every type would be 'portable' and could be plugged into any schema.

@abhiaiyer91
Copy link
Author

abhiaiyer91 commented Apr 24, 2016

Could I see a sketch of this?

Ideally, we'd like to be able to compose both type definitions and resolve functions, such that every type would be 'portable' and could be plugged into any schema.

Having trouble visualizing this in my head!

@abhiaiyer91
Copy link
Author

Yes the above could already be done today and could be just shipped as utilities.

@stubailo
Copy link
Contributor

Should we move this to https://github.com/apollostack/graphql-tools? Seems more relevant to the server component!

@abhiaiyer91
Copy link
Author

yes def!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants