Comments (11)
Regarding the makeExecutableSchema
API:
The schemaDirectives
option is dedicated to the legacy schema directives. https://www.graphql-tools.com/docs/legacy-schema-directives/
What you will have to do is to declare the directive in SDL:
import { makeExecutableSchema } from "graphql-tools";
const schema = makeExecutableSchema({
typeDefs: /* GraphQL */ `
type Query {
hi: String!
}
# the directive must be declared manually via SDL
# as there is no way to provide the GraphQLLIveDirective exported
# from @n1ru4l/graphql-live-query with makeExecutableSchema
directive @live(if: Boolean) on QUERY
`,
resolvers: {
Query: {
hi: () => "hello"
}
}
});
You don't need to provide any directive handler as the InMemoryLiveQueryStore is already capable of handling the directive.
This should probably be better documented as graphql-tools is a popular library. I will try to do that soon. π
Regarding the statement: "@n1ru4l/socket-io-graphql-server does not export pubsub"
PubSub is not something the GraphQL network layer should provide. This might be confusing at first for people coming from apollo which is trying to address most use-cases with its bloated apollo-server.
Subscriptions can but must not be implemented with PubSub. Subscriptions need a source which could be anything that can be wrapped in an AsyncIterable. The graphql subscription engine then subscribes to the AsyncIterable.
The most popular implementation is probably https://github.com/apollographql/graphql-subscriptions which is basically a PubSub wrapped in an AsyncIterable.
If you only have one GraphQL server instance, you might not even need it: apollographql/graphql-subscriptions#240 (comment)
https://github.com/n1ru4l/graphql-bleeding-edge-playground has an example of setting up a PubSub based on Node.js EventEmitter.
Please let me know whether this answered your questions and feel free to ask any further questions or point out stuff that should be better documented.
from graphql-live-query.
Hey @goodnewso, could you provide some feedback on whether the information above could solve your issues?
from graphql-live-query.
Hey @goodnewso, could you provide some feedback on whether the information above could solve your issues?
I will give an update on that soon. please
from graphql-live-query.
The help was ok
I will try my best to highlight the possible issues am having. but first I will want to say thank you for the assistance. I had some serious issues with my system just got it fixed.
- am using multiple instances of Graphql server because I could not find any documentation or example on how to enable introspection or playground or graphiql in the graphql socketio server.
- Comming from apollo-server. apollo documentation states that default pubsub which uses event emitter should not be used in production. so my question is the pubsub you created in dungeon reveavler. is it production-ready, can it be scale using Redis or anything?
- in your example Lazy Socket Authentication You only give an example if the client would send token or authentication through socket but not through graphql mutation. I think an example for both client and server is needed. for clarity
I think some simple examples and documentation for both client and servers will ease the ground query, mutation, subscription and, live query. but thanks for the help so far.
from graphql-live-query.
am using multiple instances of Graphql server because I could not find any documentation or example on how to enable introspection or playground or graphiql in the graphql socketio server.
Introspection is not necessarily tied to the GraphQL server, but rather to the execution engine the server is using. "Introspection" is just another GraphQL query that is executed against the GraphQL schema. See https://github.com/graphql/graphql-js/blob/7f40198a080ab3ea5ff3e1ecc9bf7ade130ec1bf/src/utilities/getIntrospectionQuery.js#L25
So GraphiQL or GraphQL Playground are simply executing an introspection query against the configured endpoint schema.
In GraphiQL you can pass a fetcher
function into the GraphiQL
component. You can find an example fetcher function for the socket-io transport over here: https://github.com/n1ru4l/graphql-bleeding-edge-playground/blob/90c1d1c089b95578fd5d45a1564ff32747fcb977/src/dev/GraphiQL.tsx#L22-L26
You can simply pass it to your GraphiQL instance https://github.com/n1ru4l/graphql-bleeding-edge-playground/blob/90c1d1c089b95578fd5d45a1564ff32747fcb977/src/dev/GraphiQL.tsx#L210-L212
In general, https://github.com/n1ru4l/graphql-bleeding-edge-playground shows how you can set up GraphiQL as a development-only route within create-react-app (and it should be applicable to any other setup).
Comming from apollo-server. apollo documentation states that default pubsub which uses event emitter should not be used in production. so my question is the pubsub you created in dungeon reveavler. is it production-ready, can it be scale using Redis or anything?
It depends on your use case. If you don't need to scale horizontally and only have one instance of your GraphQL server running you don't need something like Redis. dungeon-revealer for example is an isolated service that uses SQLite and does not need any external services/databases/scaling with minimum traffic. So in that case having an in-memory PubSub is perfectly fine. The highest load I ever had on an instance at the same time is 10 users. You might re-evaluate based on your concurrent user count/load.
However, nobody is stopping you from using https://github.com/apollographql/graphql-subscriptions or https://github.com/davidyaha/graphql-redis-subscriptions TBH I think their naming is very misleading as the packages CAN be used with any other library that can benefit from pub subs wrapped in AsyncIterables.
in your example Lazy Socket Authentication You only give an example if the client would send token or authentication through socket but not through graphql mutation. I think an example for both client and server is needed. for clarity
It is possible to do authentication via a mutation. For that, you would however have to not use the lazy socket authentication at all.
The implementation could look similar to this:
// we use a weak map to avoid memory leaks
// so once a socket disconnects the value is purged from the map here
const authenticatedSockets = new WeakMap();
registerSocketIOGraphQLServer({
socketServer,
getParameter: ({ socket }) => ({
graphQLExecutionParameter: {
schema,
rootValue,
contextValue: {
// this is the socket that executes the operation
socket,
// a global lookup map of the authenticated sockets
authenticatedSockets,
// some auth service that is used for getting the user data for given credentials
authService
}
}
})
});
And the given resolvers (I picked a resolver map graphql-tools style), you can use whatever approach you prefer.
const Mutation = {
authenticate: (_, args, context) => {
const userInfo = context.authService(args.credentials);
if (userInfo) {
authenticatedSockets.set(context.socket, userInfo);
}
},
doSomething: (_, args, context) => {
const userInfo = context.authenticatedSockets.get(context.socket);
if (!userInfo) {
throw new Error("Not authenticated :(");
}
if (!userInfo.isAdmin) {
throw new Error("Insufficient permissions :(");
}
}
};
from graphql-live-query.
Wonderful
from graphql-live-query.
The directive usage with graphql-tools is now documented over here: https://github.com/n1ru4l/graphql-live-query/blob/main/packages/graphql-live-query/README.md#graphqllivedirective
GraphiQL fetcher setup is documented here: https://github.com/n1ru4l/graphql-live-query/blob/main/packages/socket-io-graphql-client/README.md#graphiql-fetcher
from graphql-live-query.
If I may suggest, one more tool should also be documented which is Graphql Code Generator.
from graphql-live-query.
Why should it be documented? GraphQL code generator is a tool unrelated to graphql-live-query.
from graphql-live-query.
Why should it be documented? GraphQL code generator is a tool unrelated to graphql-live-query.
sorry, i was referring to @n1ru4l/socket-io-graphql-server not graphql-live-query.
from graphql-live-query.
@n1ru4l/socket-io-graphql-server does not use graphql-codegen. I think all open questions here are answered, thus I will close this issue. If you have additional questions please open a new discussion.
from graphql-live-query.
Related Issues (20)
- CPU and RAM going crazy with Socket.IO HOT 2
- Dependency Dashboard
- `createLiveQueryPatchGenerator` shouldn't yield empty patches HOT 4
- Improve package publishing HOT 10
- extractLiveQueryRootFieldCoordinates doesn't respect 'idFieldName' option. HOT 3
- json-diff-plus replaces keys with 'undefined' instead of deleting them HOT 1
- InMemoryLiveQuery store doesn't respect previous `setExecuteFn`s by other envelop plugins HOT 2
- Website HOT 1
- No package can be imported from CRA + TS projects HOT 7
- Typescript definition files seems to be wrong HOT 2
- Unsubscribe/dispose doesnβt work with applyLiveQueryJSONDiffPatchGenerator HOT 3
- Postgres Example using `@graphile/lds` for invalidations
- Multi-argument custom query invalidation doesn't seem to work HOT 6
- [Question] Recommended approach for invalidating lists after a change? HOT 1
- [Question] How to use jsondiffpatch with apollo-client? HOT 1
- Make graphql-live-query unaware of the GraphQL schema
- Yarn Pnp: @n1ru4l/graphql-live-query tried to access tslib HOT 5
- List query doesn't get updated HOT 1
- Invalidation should trigger a call to getParameter to get a fresh context HOT 9
- Leak? HOT 1
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-live-query.