Comments (14)
No, it is not obsolete. The subscriptions will stop working if you delete it.
from apollo-universal-starter-kit.
Opened 2 browsers and tried it out. Still working..
from apollo-universal-starter-kit.
@mitjade Yes you are right, actually subscriptions server is set up in api_server.js
, so I think websockets_server.js
is outdated indeed.
from apollo-universal-starter-kit.
Found this out by accident. Will create PR.
Am trying to add mqtt client so I would be able to publish mqtt events in mutations and still keep existing subscriptions, but can not seem to set it in a way to not have it restart on page reload or hot code reload, but still be able to expose client publish in schema.
I know this has nothing to do with this starter kit, but if you have any short pointers on how to archive this, would really appreciate it. If not np.
from apollo-universal-starter-kit.
@mitjade I have no idea. If you could show me the code, that reveals the problem with hot code reload, I might be able to look when I will have time. I believe even making subscriptions in this starter kit to hot reload code changes in counter mutation code without restarting subscriptions might not be possible. Generally subscriptions need to be made hot code reload friendly first.
from apollo-universal-starter-kit.
Thx. Will prepare something in a fork, if I will not be able to figure this out.
from apollo-universal-starter-kit.
Here is an example of what I'm trying accomplish.
Start an MQTT client and subscribe to specific topics, which I managed to get working.
What I am not able to do, is to export a publish function in src/server/api/mqtt_client.js
that I could then call when a certain Mutation is triggered.
If I call it as demonstrated in src/server/api/schema.js
, if you press the 'Click to increase count', I get an:
error { TypeError: _mqtt_client2.default.publish is not a function
I tried a few different approaches, all unsuccessful, so it looks like I still need to learn a few things on how javascript works...
from apollo-universal-starter-kit.
Another approach was:
src/server/api/schema.js
...
Mutation: {
addCount(_, { amount }, context) {
const client = mqttClient();
client.publish('topic', 'message');
Here I get:
error { TypeError: Cannot read property 'on' of undefined
from apollo-universal-starter-kit.
Yes, you are certainly doing something wrong, why your src/server/api/mqtt_client.js
closure has parameter mqttClient
, e.g. export default (mqttClient) =>
, where do you pass this parameter to your closure? You don't pass it at all
from apollo-universal-starter-kit.
You should call your mqtt_client.js
module like this:
mqttClient(realMqttClientInstance).publish('topic', 'message');
from apollo-universal-starter-kit.
How do I export the mqttClient
instance from the src/server/api_server.js
so I can access it in src/server/api/schema.js
?
from apollo-universal-starter-kit.
export default mqttClient;
in the src/server/api_server.js
.
Sorry for a stupid question :) will try it out now.
from apollo-universal-starter-kit.
I believe the way to do it is to use Apollo GraphQL context, see file middleware/graphql.js
you should pass an instance of your mqttClient as parameter there, e.g.
app.use('/graphql', (...args) => graphqlMiddleware(mqttClient)(...args));
export default mqttClient => graphqlExpress(() => {
return {
schema,
context: {
Count: new Count(),
mqttClient: mqttClient
},
};
});
And then in your GraphQL schema you will be able to access mqttClient from context, the same way new Count()
instance is accessed from context
from apollo-universal-starter-kit.
Managed to get it working!
Thank you AGAIN for the help!!! I would probably keep banging my head agains the wall with this problem for quite a while. I guess I need to read up on some javascript fundamentals :)
from apollo-universal-starter-kit.
Related Issues (20)
- Multi Config Setup HOT 2
- Can't fully install dependencies after fresh download - expo-yarn-workspace postinstall fails HOT 4
- lerna stdout maxBuffer exceeded HOT 7
- [Question] Are there any plans to shift to any other package manager since lerna is no longer properly maintained. HOT 5
- Unable to perform a full page reload on edit post page in React Client. HOT 2
- Tests fail after clean installation
- feedback
- Update dependency react-navigation HOT 1
- How can i connect it with my Hasura database?
- Plans to upgrade to webpack 5 HOT 3
- Fail to build on a clean Fedora 33 installation
- Expo Go Android will not run. Says wrong sdk version of expo HOT 1
- New @server app dependencies install error (ambiguous syntax error)
- Standalone use
- master does not work
- Upgrade expo to latest SDK HOT 6
- Setting i18n debug to true reveals several potential issues
- Router is not worked ! HOT 6
- ..
- Demo app link on the readme file not working HOT 3
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 apollo-universal-starter-kit.