Comments (8)
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.
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.
Accomplished this a while ago for the discourse loaders and it looks quite neat, so I'm closing this issue.
from graphql-tools.
This is taken care of by PR #27
Refactoring the discourse loaders will be done when everything is ready.
from graphql-tools.
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.
The main reason I did it this way was because the loaders are a pet-request thing:
- They depend on login state since they need to pass through Auth tokens
- 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.
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.
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)
- Project Roadmap HOT 2
- Drop dependency on fast-url-parser HOT 2
- DEBUG=1 results in console.time() warnings
- @graphql-tools/mock does not work with Vitest HOT 5
- Deterministic (seeded) enum values
- Stitching: object field is null when all selections are delegated
- Http Executor encodes headers into query parameters which can leak Authorization headers
- Ability to get names of all the stitched queries in a middleware
- requireResolversToMatchSchema: 'warn' throws an error
- Support .astro file loading on graphql-tag-pluck HOT 1
- Troubles with connectionParams on subscriptions
- Adding content-type header is not supported when fetching schema
- Query does not provide a operation name as a property in the request body causing some server configurations to reject the request
- @graphql-tools/mock 9.0.1 causes panic: Internal errors HOT 2
- @graphql-tools/merge directive arguments compare should not require identical ordering HOT 1
- load babel options in `graphql-tag-pluck`
- [mock] relayStylePaginationMock sometimes returns an incorrect value for hasNextPage
- Batch execution throws an error when Array.prototype has additional property
- Federation @join__field requires parameter handling improvement
- filterSchema argumentFilter provides incorrect typeName
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 graphql-tools.