GithubHelp home page GithubHelp logo

Minimal loader example about graphql-tools HOT 8 CLOSED

ardatan avatar ardatan commented on April 30, 2024
Minimal loader example

from graphql-tools.

Comments (8)

helfer avatar helfer commented on April 30, 2024 1

My current plan:

  • Allow declaring a root resolve function for the schema, which is run before every query or mutation.
  • write an attachLoadersToContext function that attaches loaders to context. Can be used with any GraphQL schema.
  • write a apolloServer(shorthand, resolvers, loaders) function, which calls the right things under the hood.

from graphql-tools.

helfer avatar helfer commented on April 30, 2024 1

I just want to avoid having too much magic on day 1, because I think it will give people the impression that our thing is very different from plain graphql-js. For the shorthand schema, that's a good thing because our solution feels much better. For the loaders it seems like an unnecessary complication.

from graphql-tools.

helfer avatar helfer commented on April 30, 2024 1

Accomplished this a while ago for the discourse loaders and it looks quite neat, so I'm closing this issue.

from graphql-tools.

helfer avatar helfer commented on April 30, 2024

This is taken care of by PR #27

Refactoring the discourse loaders will be done when everything is ready.

from graphql-tools.

helfer avatar helfer commented on April 30, 2024

Reopening this issue because I'm not quite happy with the current implementation. I just tried imagining how I would explain to people that connectors get attached to the context and realized that this will be really confusing for almost everyone.
I think the only reason we were even going in this direction is because we didn't want the resolvers file to have any imports. That may still be an eventual goal if we want to offer this as a service, but for the alpha milestone I actually think it might be better to just import the connectors in the resolvers, because that's straightforward JavaScript, and nobody will find it magic.
Once we have a good argument for attaching connectors to context, we can start doing it and promoting it. A good reason might be providing default connectors which don't require people to define resolvers at all.

PS: I'm calling them connectors now, I think it fits better, because they're at a higher level of abstraction than the loaders.

from graphql-tools.

stubailo avatar stubailo commented on April 30, 2024

The main reason I did it this way was because the loaders are a pet-request thing:

  1. They depend on login state since they need to pass through Auth tokens
  2. They have per request caching

If you just import them then you don't get the per-request state which I think is pretty crucial. I don't think it had anything to do with a service.

from graphql-tools.

helfer avatar helfer commented on April 30, 2024

Yeah, I get that, but I think we can achieve the same with a singleton and it will be less verbose. What do you think?

from graphql-tools.

stubailo avatar stubailo commented on April 30, 2024

If you can, then great! As long as it's also easy to understand. I find Meteor's per-request singletons that switch out using bindEnvironment pretty hard to work with, personally.

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.